TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Rajeev Kumar
NA
334
138.2k
post back problem
Jun 14 2013 9:10 AM
im using this code
........................................................
SqlConnection sqcon = new SqlConnection("Data Source=ADMIN-PC;Initial Catalog=raj;Integrated Security=True");
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
BindRepeaterData();
}
Validate();
}
protected void Button1_Click(object sender, EventArgs e)
{
sqcon.Open();
SqlCommand cmd =new SqlCommand("insert into repeter_demo(User_Name,Subject,comment,Post_Date)values(@User_Name,@subject,@Comment,@Post_Date )", sqcon);
cmd.Parameters.AddWithValue("@User_Name", TextBox1.Text);
cmd.Parameters.AddWithValue("@Subject", TextBox2.Text);
cmd.Parameters.AddWithValue("@Comment", TextBox3.Text);
cmd.Parameters.AddWithValue("@Post_Date", DateTime.Now);
cmd.ExecuteNonQuery();
sqcon.Close();
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
TextBox3.Text = string.Empty;
BindRepeaterData();
}
//Bind Data to Repeater Control
protected void BindRepeaterData()
{
sqcon.Open();
SqlCommand cmd = new SqlCommand("select * from repeter_demo Order By Post_Date", sqcon);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(ds);
Rpt.DataSource = ds;
Rpt.DataBind();
sqcon.Close();
}
}
after each post back new row of repeater show on the page. while controls are empty .
im using this code at designing phase
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Enter Name </td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td>Enter Subject</td>
<td><asp:TextBox ID="TextBox2" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td valign="top"> Enter Comment</td>
<td> <asp:TextBox ID="TextBox3" runat="server" Rows="5" Columns="15" TextMode="MultiLine"></asp:TextBox></td>
</tr>
<tr><td>
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" /></td></tr>
</table>
</div>
<div>
<asp:Repeater ID="Rpt" runat="server">
<HeaderTemplate>
<table cellpadding="0">
<tr>
<td colspan="2"> <b>Comment</b></td></tr>
</HeaderTemplate>
<ItemTemplate>
<tr style="background-color:Gray">
<td>
<table style="background-color:Yellow; border-top:1px dotted silver; width:500px">
<tr>
<td> Subject:<asp:Label ID="lblSubject" runat="server" Text='<%#Eval("Subject")%>' Font-Bold="true"></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblcomment" runat="server" Text='<%#Eval("Comment") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
<table style="background-color:#EBEFF0;border-top:1px dotted #df5015;border-bottom:1px solid
#df5015; width:500px" >
<tr>
<td>
Post By: <asp:Label ID="lblUser" runat="server" Font-Bold="true" Text='<%#Eval("User_Name") %>'/>
</td>
<td>
Created Date:<asp:Label ID="lblDate" runat="server" Font-Bold="true" Text='<%#Eval("Post_Date")
%>'/>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
how will i get rid of this problem .
at out put i want to clear repeter clear.
Reply
Answers (
1
)
gridview binding dynamically
Multiple ASP.NET Membership roles in the same Website