asp.net get the line number of the current line in ListView and GridView _ Practical Tips

Source: Internet
Author: User

The example in this article describes the line number that asp.net gets listview and the current row in the GridView. Share to everyone for your reference, specific as follows:

aspx, in Gridview/listview, there is a template column called LinkButton, and when you click it, get the index value of the row it is in

In ListView:

First type:

<ItemTemplate>
 <tr>
  <td>
  <asp:linkbutton runat= "Server" id= "btnselected" text= " <%# (container.displayindex+1). ToString ()%> ' ></asp:LinkButton>
   </td>
 </tr>
</ItemTemplate>

The second type:

<ItemTemplate>
 <li>
  <asp:linkbutton id= "Btndelete" runat= "Server" Commandname= "Delete"
   text= "<%# container.dataitem%>" ></asp:LinkButton>
 </li>
</itemtemplate >

In the GridView

First type:

<itemtemplate>
  <asp:linkbutton id= "LinkButton1" runat= "Server"
</itemtemplate>

protected void LinkButton1_Click (object sender, EventArgs e)
{
  //line number
  int row = ((GridViewRow) ((LinkButton) Sender). NamingContainer). RowIndex;
}

The second type:

<asp:gridview id= "gvtest" runat= "Server" >
  <Columns>
  <asp:TemplateField>
  < Itemtemplate>
  displayindex: <%# container.displayindex%> | | Dataitemindex: <%# container.dataitemindex%><br/>
  </ItemTemplate>
  </asp: templatefield>
  </Columns>
</asp:GridView>

I hope this article will help you to ASP.net program design.

Related Article

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.