问题描述
我正在使用gridview,因为我使用链接按钮.但是我没有单击链接按钮的行索引.所以请帮帮我.
int索引= System.Convert.ToInt32(e.CommandArgument);
LinkButton link_button =(LinkButton)GridView1.Rows [index] .FindControl("link1");
标签l1 =(Label)GridView1.Rows [index] .FindControl("Label2");
在网格的列字段中.我用......
i am using the gridview in that i use the link button. but i don`t get the row index for the clicked the link button. so please help me.
int index = System.Convert.ToInt32(e.CommandArgument);
LinkButton link_button =(LinkButton)GridView1.Rows[index].FindControl("link1");
Label l1 = (Label)GridView1.Rows[index].FindControl("Label2");
in column filed of grid. i use......
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("title")%>' Visible="false"></asp:Label>
< asp:LinkButton ID ="link1" runat ="server" Text =''<%#Eval("title")%>''CommandName ="link" ForeColor ="Blue">
<asp:LinkButton ID="link1" runat="server" Text=''<%#Eval("title")%>'' CommandName="link" ForeColor="Blue">
</ItemTemplate>
<ItemStyle ForeColor="Blue" Font-Size="Medium" />
</asp:TemplateField>
推荐答案
<asp:LinkButton ID="LinkButton1" runat="server" Text="Add to cart"
OnClick="LinkButton1_Click" CommandArgument='<%# Container.DataItemIndex %>' />
然后,您可以在后面的代码中像这样检索它:
You can then retrieve it like this in the code behind:
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton myButton = sender as LinkButton;
if (myButton != null)
{
string rowIndex = myButton.CommandArgument;
// use this rowIndex now as per your need
}
}
发送方持有对触发事件处理程序的LinkButton
的引用.
您可以将对象转换为LinkButton
,然后检索其CommandArgument
并将其转换为字符串.
The sender holds a reference to the LinkButton
that triggered the event handler.
You can cast the object into a LinkButton
and then retrieve its CommandArgument
and cast that into string.
这篇关于链接按钮无法在gridview中获取行索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!