手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >Repeater事件OnItemCommand取得行内控件的方法
Repeater事件OnItemCommand取得行内控件的方法
摘要:记录一下,主要是这句:TextBoxtxtNum=e.Item.FindControl("txtNum")asTextBox;Repeate...

记录一下,主要是这句:

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取得行内控件的方法】相关文章:

把某个asp.net 控件替换成自定义控件的方法

DataList 中动态绑定服务器子控件的代码

c#中实现文件拖放打开的方法

asp.net通过配置文件连接Access的方法

asp.net下文件上传和文件删除的代码

ASP.NET页面按钮单击事件失效的解决方法

asp.net querystring乱码解决方法

ASP.NET动态加载用户控件的实现方法

repeater分页 内容显示

asp.net webservice返回json的方法

精品推荐
分类导航