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