ASP.net的GridView:得到LinkItem的排 [英] ASP.net GridView: get LinkItem's row
问题描述
我要显示删除,在GridView控件的 registred用户的链接,所以我使用的TemplateField:
I want to show "Delete" link in GridView to registred users, therefore I am using templateField:
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" OnSorting="GridView_Sort">
<Columns>
<asp:TemplateField HeaderText="Control">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" onClick="deleteEntry()" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
现在在我的deleteEntry()函数,我怎么能知道行任何在删除被点击的链接?如何为GE例如rowIndex位置?
Now in my deleteEntry() function how can I know anything about the row in which "Delete" link was clicked? How to ge for e.g. rowindex?
推荐答案
您可以接近这个略有不同。你看,当一个控件放在 一个gridview里面,从控制提出的任何事件也 RowCommand
引发的GridView控件。
You could approach this slightly different. You see, when a control is placed inside a gridview, any event raised from that control raises also the RowCommand
on the GridView.
要得到你想要的,那么你可以添加什么都的CommandName
和 CommandArgument
你的 LinkButton的
,然后抓住它在GridView的RowCommand。
To get what you want you could then add both CommandName
and CommandArgument
to your LinkButton
and then catch it in the GridView's RowCommand.
<asp:LinkButton id="LinkButton1" runat="server" commandName="LinkButtonClicked" commandArgument='Eval("myObjectID")' />
其中, myObjectID
是绑定的网格对象的ID列的名称。
where myObjectID
is the name of the ID column of your object you bind the grid to.
然后
void GridView1_RowCommand( object sender, GridViewCommandEventArgs e )
{
if ( e.CommandName == "LinkButtonClicked" )
{
string id = e.CommandArgument; // this is the ID of the clicked item
}
}
这篇关于ASP.net的GridView:得到LinkItem的排的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!