日期:2014-05-18  浏览次数:20455 次

repeater控件中button按钮事件的使用
用repeater控件读取数据库数据,想在repeater中添加一个button按钮和一个Textbox,目的是当单击button按钮时,将从Textbox中读到的数据更新到数据库,一直不知如何实现。对commandname和conmmandargument也不太理解。谢谢回答,最好能有示例代码。

------解决方案--------------------
<div>
 <asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<ul>
<li>
<%#Eval("id") %></li>
<li>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:Button ID="Button3" runat="server" CommandName="Insert" CommandArgument='<%#Eval("id") %>' Text="添加" /></li>

</ul>
</ItemTemplate>
</asp:Repeater>
</div>



protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
int id = int.Parse(e.CommandArgument.ToString());
string str = ((TextBox)e.Item.FindControl("TextBox3")).Text;

//插入数据库
}
}