更新在转发器中不起作用

编程入门 行业动态 更新时间:2024-10-10 04:19:58
本文介绍了更新在转发器中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

推荐答案

在Page_Load上调用绑定方法() Call Bind Method on Page_Load() 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(); } }

更多推荐

更新在转发器中不起作用

本文发布于:2023-11-14 03:54:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586140.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转发器   中不

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!