The method of Repeater event OnItemCommand to obtain the control of the line

Source: Internet
Author: User
Tags eval

This article mainly introduced the Repeater event OnItemCommand obtains the line internal control method, the need friend may refer to the

Record, mainly this sentence:

TextBox txtnum = E.item.findcontrol ("Txtnum") as TextBox;

Repeater is so strong, so flexible. I don't need anything other than repeater.

The code is as follows:

<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= "Update" commandname= "Updates" commandargument= ' <% #Eval (" PID ")%> '/></td>

</tr>

</ItemTemplate>

</asp:Repeater>

</table>

The code is as follows:

protected void Rptlist_itemcommand (object source, RepeaterCommandEventArgs e)

{

Switch (e.commandname)

{

Case "Update":

string arg = E.commandargument.tostring ();//Get Parameters

It is useful to find the control of the line that fires the event, and to pass on more of the required parameter values.

TextBox txtnum = E.item.findcontrol ("Txtnum") as TextBox;

Perform business logic below

String jsstr = "<script>alert (' Delete succeeded!" + Txtnum.text + "') </script>";

Page.ClientScript.RegisterClientScriptBlock (this. GetType (), "alert", Jsstr,false);

Break

}

Bind ();

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.