ASP. NET adds a button to the Repeater control

Source: Internet
Author: User

There are two ways to add a method to repeater:

The first is to add the OnItemCommand event to the row of the Repeater control, and there are two ways to add it

1. On the design page, select the Repeater control right-click the event label (lightning symbol) in the ==> Property ==> Property Bar ==> Double-click ItemCommand

2. It is also possible to write code.

<asp:repeater id="rptdatalist"runat="Server"OnItemCommand="Rptdatalist_itemcommand"> <ItemTemplate> <tr> <td> <asp:linkbutton id="lbncopy"runat="Server"Commandargument='<% #Eval ("Conferenceno")%>'Commandname= "Copy" > Write </asp:LinkButton> </td> <td align="Center"> <a href="#"> <% #Eval ("Conferenceno")%></a> </td> <td> <% #Eval ("conferencests")%> </td> <td align=" Right"> <% #Eval ("Confstarttime")%> </td> <td> <% #E Val"Conferencename")%> </td> <td> <% #E Val"Casename")%> </td> <td> <% #E Val"Estmamount")%> </td> <td> <% #E Val"Holdingmode")%> </td> <td align="Center"> <% #Eval ("Risklevel")%> </td> <td align="Center"> <% #Eval ("salescategory")%> </td> <td> <% #E Val"Custcd")%> </td> <td> <% #E Val"CustName")%> </td> <td> <% #E Val"productiondept")%> </td> <td> <% #E Val"holdingdept")%> </td> <td> <% #E Val"Projectno")%> </td> <td> <% #E Val"ProjectName")%> </td> <td> <% #E Val"Role")%> </td> <td> <% #E Val"Votedeliberresult")%> </td> <td align="Center"> <% #Eval ("Vote")%> </td> </tr> </ItemTemplate> </asp:Repeater>

Now the event is registered for the Repeater line, but we are going to implement its internal button function, there is how to judge us to manipulate the row, here is the main use of the CommandArgument property, set CommandArgument bound primary key field, CommandName is primarily used to differentiate which operation is performed on this line. Page code as above, now say. CS Code:

protected void Rptdatalist_itemcommand (object  source, RepeaterCommandEventArgs e)        {              If"copy")             {                string L_strconferenceno = E. Commandargument.tostring ();            }        }

Second: Add the OnClick event to the button

<asp:repeater id="rptdatalist"runat="Server"> <ItemTemplate> <tr> <td> <asp:linkbutton id="lbncopy"runat="Server"onclick="Lbncopy_click"Commandargument='<% #Eval ("Conferenceno")%>'Commandname="Copy"> Write </asp:LinkButton> </td> <td align="Center"> <a href="#"> <% #Eval ("Conferenceno")%></a> </td> <td> <% #Eval ("conferencests")%> </td> <td align=" Right"> <% #Eval ("Confstarttime")%> </td> <td> <% #E Val"Conferencename")%> </td> <td> <% #E Val"Casename")%> </td> <td> <% #E Val"Estmamount")%> </td> <td> <% #E Val"Holdingmode")%> </td> <td align="Center"> <% #Eval ("Risklevel")%> </td> <td align="Center"> <% #Eval ("salescategory")%> </td> <td> <% #E Val"Custcd")%> </td> <td> <% #E Val"CustName")%> </td> <td> <% #E Val"productiondept")%> </td> <td> <% #E Val"holdingdept")%> </td> <td> <% #E Val"Projectno")%> </td> <td> <% #E Val"ProjectName")%> </td> <td> <% #E Val"Role")%> </td> <td> <% #E Val"Votedeliberresult")%> </td> <td align="Center"> <% #Eval ("Vote")%> </td> </tr> </ItemTemplate> </asp:Repeater>
protected void Lbncopy_click (object  sender, EventArgs e)        {            string l_ Strconferenceno=((LinkButton) sender). Commandargument.tostring ();        }

ASP. NET adds a button to the Repeater control

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.