Discussions Board In Asp.net Using Repeater control
Discussions Board In Asp.net Using Repeater control
Step1:Design DataBase Tables
Here I am using table Question for data binding in Repeater
control .
Its Table structure is below.
CREATE TABLE [dbo].[question](
[id] [int] IDENTITY(1,1) NOT NULL,
[subject] [varchar](max) NULL,
[body] [varchar](max) NULL,
[posted_date] [datetime] NULL,
[posted_by] [varchar](50) NULL,
[is_active] [bit] NULL,
[no_count] [int] NULL,
[last_lookup] [datetime] NULL
) ON [PRIMARY]
Step2:Design web form .aspx page
<div>
<br />
<asp:Repeater ID="RepDetails"
runat="server">
<HeaderTemplate>
<table
class="txt"
width="60%">
<tr
style="background-color: #df5015; color: White">
<td colspan="2">
<b>All DissCussion</b>
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr
style="background-color: #EBEFF0">
<td>
<table class="main">
<tr>
<td>
Subject:
<asp:Label ID="lblSubject"
runat="server"
Text='<%#Eval("Subject") %>' Font-Bold="true"
/>
</td>
<td>
<asp:HiddenField ID="hd" Value='<%#Eval("id") %>' runat="server"
/>
<%--<asp:LinkButton ID="lnkRead"
Text="raed" runat="server" OnClick
="lnk"></asp:LinkButton>--%>
<%--<asp:Button ID="Button1"
runat="server" Text="Button" OnClick =
"Button_Click" CommandArgument = '<%# Eval("id") %>'
/>--%>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td
class="t">
<asp:Label ID="lblComment" runat="server" Text='<%#Eval("body") %>' /><asp:LinkButton
ID="lnk_read"
runat="server"
Text="...Continue
Reading" OnClick="read_Click"></asp:LinkButton>
</td>
</tr>
<tr>
<td>
<table width="60%">
<tr class="fotr">
<td align="left">
Post By:
<asp:Label ID="lblUser"
runat="server"
Font-Bold="true"
Text='<%#Eval("posted_by") %>' />
</td>
<td align="right">
Created
Date:<asp:Label ID="lblDate"
runat="server"
Font-Bold="true"
Text='<%#Eval("Posted_date") %>' />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td
colspan="2">
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
Step3:Login on .Cs page
protected void Page_Load(object sender, EventArgs
e)
{
BindRepeaterData();
}
//Methos for data binding in repeater
control
protected void
BindRepeaterData()
{
con.Open();
SqlCommand cmd = new
SqlCommand("select
LEFT (body ,150) as body,* from question where is_active=1", con);
DataSet ds = new DataSet();
SqlDataAdapter da = new
SqlDataAdapter(cmd);
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
RepDetails.Visible = true;
RepDetails.DataSource = ds;
RepDetails.DataBind();
}
else
{
RepDetails.Visible = false;
}
con.Close();
}
//Button Event ,Here you can fetch any
value ,those you wanna use.
protected void
read_Click(object sender, EventArgs e)
{
//Get the reference of the clicked button.
LinkButton button = (sender as LinkButton);
//Get the command argument
string commandArgument = button.CommandArgument;
HiddenField hd =
button.NamingContainer.FindControl("hd")
as HiddenField;
Session["diss_id"] =
hd.Value;
Response.Redirect("disscussion.aspx");
}
Comments
Post a Comment