create a database demo and add table PostMaster
table contain the columns "postid(pk),post,postdate"
Step 1: Create StyleSheet "Default.css"
.table
{
width: 60%;
border-radius: 14px;
-moz-border-radius: 14px;
-webkit-border-radius: 14px;
border: 1px groove #B7B7B7;
margin-left: 108px;
vertical-align: text-top;
background-color: #CACACA;
}
.td
{
height: 79px;
text-align:center;
}
.link
{
text-decoration:none;
font-weight:bold;
background: #0571A6;
background: -moz-linear-gradient(top,#73AEC9 0,#73AEC9 1px,#338AB0 1px,#0571A6 100%);
background: -webkit-gradient(linear,left top,left bottom,color-stop(0,#73AEC9),color-stop(5%,#73AEC9),color-stop(5%,#338AB0),color-stop(100%,#0571A6));
background: #0571A6;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#338AB0',endColorstr='#0571A6',GradientType=0);
border-color: #045A8B;
color: white!important;
margin-left: 0px;
margin-right:20px;
}
.divPost
{
height: 104px;
}
.divborder
{
margin-top:23px;
border-top:groove 1px #CACACA;
}
.divcontent
{
margin-top:10px;
width: 532px;
}
.PostTable
{
border:1px groove #C0C0C0;
border-radius: 11px;
margin-bottom:8px;
text-align:justify;
margin-left:20px;
-moz-border-radius: 11px;
-webkit-border-radius: 11px;
background-color:#EDFAEF;
width:500px;
height:100px;
}
Step 2: Create an asp webform "Sharing.aspx"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sharing.aspx.cs" Inherits="ASP_NET.Examples.Sharing" %>
<%@ Register src="BlogPost.ascx" tagname="BlogPost" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Wall Post Example</title>
<link href="Default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="divPost">
<table class="table">
<tr>
<td class="td">
<asp:TextBox ID="txtPost" runat="server" style="margin-top:10px" Height="50px"
Width="554px" TextMode="MultiLine"></asp:TextBox>
<p align="right" style="margin-top:5px;">
<asp:RequiredFieldValidator ID="RFV" runat="server" style="float:left; margin-left: 23px;"
ErrorMessage="Enter Text First" ControlToValidate="txtPost"
ForeColor="White"></asp:RequiredFieldValidator>
<asp:Button ID="btnPost" runat="server" CssClass="link" Text="Post"
Width="91px" onclick="Button1_Click" />
</p>
</td>
</tr>
</table>
</div>
<div class="divborder">
</div>
<div class="divcontent">
<uc1:BlogPost ID="BlogPost1" runat="server" />
</div>
</form>
</body>
</html>
table contain the columns "postid(pk),post,postdate"
Step 1: Create StyleSheet "Default.css"
.table
{
width: 60%;
border-radius: 14px;
-moz-border-radius: 14px;
-webkit-border-radius: 14px;
border: 1px groove #B7B7B7;
margin-left: 108px;
vertical-align: text-top;
background-color: #CACACA;
}
.td
{
height: 79px;
text-align:center;
}
.link
{
text-decoration:none;
font-weight:bold;
background: #0571A6;
background: -moz-linear-gradient(top,#73AEC9 0,#73AEC9 1px,#338AB0 1px,#0571A6 100%);
background: -webkit-gradient(linear,left top,left bottom,color-stop(0,#73AEC9),color-stop(5%,#73AEC9),color-stop(5%,#338AB0),color-stop(100%,#0571A6));
background: #0571A6;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#338AB0',endColorstr='#0571A6',GradientType=0);
border-color: #045A8B;
color: white!important;
margin-left: 0px;
margin-right:20px;
}
.divPost
{
height: 104px;
}
.divborder
{
margin-top:23px;
border-top:groove 1px #CACACA;
}
.divcontent
{
margin-top:10px;
width: 532px;
}
.PostTable
{
border:1px groove #C0C0C0;
border-radius: 11px;
margin-bottom:8px;
text-align:justify;
margin-left:20px;
-moz-border-radius: 11px;
-webkit-border-radius: 11px;
background-color:#EDFAEF;
width:500px;
height:100px;
}
Step 2: Create an asp webform "Sharing.aspx"
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sharing.aspx.cs" Inherits="ASP_NET.Examples.Sharing" %>
<%@ Register src="BlogPost.ascx" tagname="BlogPost" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Wall Post Example</title>
<link href="Default.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="divPost">
<table class="table">
<tr>
<td class="td">
<asp:TextBox ID="txtPost" runat="server" style="margin-top:10px" Height="50px"
Width="554px" TextMode="MultiLine"></asp:TextBox>
<p align="right" style="margin-top:5px;">
<asp:RequiredFieldValidator ID="RFV" runat="server" style="float:left; margin-left: 23px;"
ErrorMessage="Enter Text First" ControlToValidate="txtPost"
ForeColor="White"></asp:RequiredFieldValidator>
<asp:Button ID="btnPost" runat="server" CssClass="link" Text="Post"
Width="91px" onclick="Button1_Click" />
</p>
</td>
</tr>
</table>
</div>
<div class="divborder">
</div>
<div class="divcontent">
<uc1:BlogPost ID="BlogPost1" runat="server" />
</div>
</form>
</body>
</html>
Step 3: Go to code file "Sharing.aspx.cs"
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
namespace ASP_NET.Examples
{
public partial class Sharing : System.Web.UI.Page
{
string connectionstring = ConfigurationManager.ConnectionStrings["DemoConnectionString"].ConnectionString;
DateTime today_date;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
today_date = DateTime.Now;
SqlConnection mycon = new SqlConnection(connectionstring);
SqlCommand mycmd = new SqlCommand("InsertPost", mycon);
mycon.Open();
mycmd.CommandType = CommandType.StoredProcedure;
mycmd.Parameters.Add("@Post", SqlDbType.NVarChar).Value = txtPost.Text;
mycmd.Parameters.Add("@PostDate", SqlDbType.DateTime).Value = today_date;
mycmd.ExecuteNonQuery();
mycmd.Dispose();
mycon.Close();
Response.Redirect("Sharing.aspx");
}
}
}
Step 4: Create Web User Control "BlogPost.ascx"
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BlogPost.ascx.cs" Inherits="ASP_NET.Examples.BlogPost" %>
<link href="Default.css" rel="stylesheet" type="text/css" />
<div id="storydiv" style="width:235px">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<ItemTemplate><table class="PostTable"><tr><td>
<asp:Label ID="lblStory" runat="server" Text='<%# Eval("Post") %>' style="text-align:justify;font-family:Calibri; color:Gray; margin-left:25px;" /></td></tr></table>
</ItemTemplate>
</asp:Repeater></div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:DemoConnectionString %>"
SelectCommand="SELECT PostId, Post, PostDate FROM PostMaster ORDER BY PostId DESC"></asp:SqlDataSource>
THANK YOU!!!! You save my life!!! thank you for this!!!
ReplyDelete