Repeater事件OnItemCommand取得行内控件的方法

古剑山,俗称 "鸡公嘴 ",山脉由贵州境内而来,最高海拔1100多米,最低海拔700多米。离开綦江县城不到10公里,映入你眼帘的是一幅墨绿的雄鸡图。在蓝天白云衬托下,鸡冠鸡嘴翅膀的轮廓线条,勾勒出雄鸡凌空屹立引颈长啼的倩影。

记录一下,主要是这句:
TextBox txtNum = e.Item.FindControl("txtNum") as TextBox;

Repeater真是太强了,太灵活。除了Repeater别的都不用。


<table>
<asp:Repeater ID="rptList" runat="server"OnItemCommand="rptList_ItemCommand">
<ItemTemplate>
<tr>
<td><asp:TextBox ID="txtNum" runat="server" Text='<%#Eval("ProNum")%>'></asp:TextBox></td>
<td><asp:Button ID="btnUpdate" runat="server" Text="更新"CommandName="update" CommandArgument='<%#Eval("PID") %>' /></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>

protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "update":
string arg = e.CommandArgument.ToString();//取得参数
//找到激发事件的行内控件,这个很有用,能将更多需要的参数值传递过来。
TextBox txtNum = e.Item.FindControl("txtNum") as TextBox; //下面执行业务逻辑
string jsStr = "<script>alert('删除成功!" + txtNum.Text + "')</script>";
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", jsStr,false);
break;
}
Bind();
}

到此这篇关于Repeater事件OnItemCommand取得行内控件的方法就介绍到这了。积极向上的心态,是成功者的最基本要素。更多相关Repeater事件OnItemCommand取得行内控件的方法内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!