Click here to Skip to main content
16,020,378 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I am working on update in repeater,but Its not working,My coding is this......

XML
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
        <HeaderTemplate>
        <table>
        <tr>
        <th>FEEDBACK</th>
        </tr>
      </HeaderTemplate>
      <ItemTemplate>
      <tr>
      <td>
          <asp:TextBox ID="TextBox1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "feedback")%>'></asp:TextBox></td>
        <td> <asp:LinkButton ID="btnaprove" Runat="server"  CommandName="Approve" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"feedback") %>'>Approve</asp:LinkButton></td>
          <td> <asp:LinkButton ID="btnupdate" Runat="server"  CommandName="Update" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"feedback") %>'>Update</asp:LinkButton></td>

          <td> <asp:LinkButton ID="btndelete" Runat="server"  CommandName="Delete" CommandArgument='<%#DataBinder.Eval(Container.DataItem,"feedback") %>'>Delete</asp:LinkButton></td>
      </td>
      </tr>
      </ItemTemplate>
        <FooterTemplate>
           </table>
        </FooterTemplate>
        </asp:Repeater>




Default.cs page...


C#
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        
         if (e.CommandName == "Update")
        {
            string str1 = ((TextBox)e.Item.FindControl("TextBox1")).Text;
            cmd = new SqlCommand("update Table1 set feedback=@feedback where status='true'", con);
            cmd.Parameters.AddWithValue("@feedback", str1);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            bind();
        }
       
    }

    private void bind()
    {
        da = new SqlDataAdapter("select feedback from Table1", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        Repeater1.DataSource = ds;
        Repeater1.DataBind();
    }

}
Posted

1 solution

Call Bind Method on Page_Load()


C#
protected void Page_Load(object sender, EventArgs e)
    {

if(!page.ispostback)
{
Bind();

}
}

Public Void Bind()
{

da = new SqlDataAdapter("select feedback from Table1", con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        Repeater1.DataSource = ds;
        Repeater1.DataBind();


}


and after Item_command as u did-

C#
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        
         if (e.CommandName == "Update")
        {
            string str1 = ((TextBox)e.Item.FindControl("TextBox1")).Text;
            cmd = new SqlCommand("update Table1 set feedback=@feedback where status='true'", con);
            cmd.Parameters.AddWithValue("@feedback", str1);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            Bind();
        }
       
    }
 
Share this answer
 
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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