Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have to add records in database through Repeater Control in ASP.NET. Could any one help me out?
Posted
Updated 1-Dec-11 18:14pm
v2

C#
<asp:repeater id="cdcatalog" runat="server" onitemcommand="cdcatalog_ItemCommand" xmlns:asp="#unknown">

<HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Name</th>
<th>Password</th>
<th>Active</th>
<th>Add</th>
</tr>
</HeaderTemplate>

<itemtemplate>
<tr>
<td><asp:label id="lbl" runat="server" text="<%#Eval("uname") %>"></asp:label> </td>
<td><![CDATA[<%#Eval("upass")%>]]> </td>
<td><asp:textbox id="text_value" runat="server" text="<%# Eval("active") %>"></asp:textbox></td>
</tr>
</itemtemplate>
<footertemplate>
<tr>
<td><asp:textbox id="textbox1" runat="server"></asp:textbox></td>
<td><asp:textbox id="textbox2" runat="server"></asp:textbox></td>
<td><asp:textbox id="textbox3" runat="server"></asp:textbox></td>
<td><asp:button id="Btn_submit" runat="server" text="Add" onclick="Btn_submit_Click" /></td>
</tr>
</footertemplate></table>

</asp:repeater>


C#
protected void cdcatalog_ItemCommand(object source, RepeaterCommandEventArgs e)
   {
       TextBox txt1 = (TextBox)e.Item.FindControl("textbox1");
       TextBox txt2 = (TextBox)e.Item.FindControl("textbox2");
       TextBox txt3 = (TextBox)e.Item.FindControl("textbox3");
       Button btn1 = (Button)e.Item.FindControl("Btn_submit");
       SqlConnection con = new SqlConnection(conn);
       if(txt1.Text!="")
       {
           string upd = "insert into login values('"+txt1.Text+"','"+txt2.Text+"','"+txt3.Text+"')";
           con.Open();
           SqlCommand cmd = new SqlCommand(upd, con);
           cmd.ExecuteScalar();
       }
           string query_login = "select * from Login";
           SqlDataAdapter da_login = new SqlDataAdapter(query_login, con);
           DataSet ds_login = new DataSet();
           da_login.Fill(ds_login);
           cdcatalog.DataSource = ds_login;
           cdcatalog.DataBind();
   }


C#
protected void Btn_submit_Click(object sender, EventArgs E)
{
}
 
Share this answer
 
Just bind the Datasource to Repeater

For your information
ASP.NET - The Repeater Control - DataBinding[^]
 
Share this answer
 
Thanks a lot thatraja & Prince Antony.....
 
Share this answer
 
Prince Antony, Thanks a lot again....
 
Share this answer
 
Comments
Prince Antony G 2-Dec-11 23:44pm    
Its ok

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900