本文介绍了更新在转发器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在处理转发器中的更新,但它无法正常工作,我的编码就是这样......



Hi I am working on update in repeater,but Its not working,My coding is this......

<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页面......









Default.cs page...


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();
    }

}

推荐答案

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();


}





和在Item_command之后你做了 -





and after Item_command as u did-

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();
        }
       
    }


这篇关于更新在转发器中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 15:40