如何从gridview中检索一行 [英] How to retrieve a row from gridview
本文介绍了如何从gridview中检索一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在单击链接按钮时从gridview(boundfields)检索行(链接按钮位于itemtemplate中)
我很难找到一个这个问题的答案很明确,
任何人都可以给出解释或解决方案。
链接也很感谢
谢谢
- 我没有谷歌:)
How to retrieve a row from gridview (boundfields) when a link button is clicked(the linkbutton is in the itemtemplate )
Im having a hard time finding a clear answer for this question,
Can anyone please give an explanation or solution.
Links are also appreciated
Thanks
--I dont have google :)
推荐答案
你可以使用 GridView.RowCommand事件 [ ^ ]为此。
因此,在GridView
中声明它。
You can use GridView.RowCommand Event[^] for this.
So, declare it insideGridView
.
<asp:GridView ID="grdYourGridView" runat="server" OnRowCommand="GridViewCommandEventHandler" />
现在声明 CommandName
和 CommandArgument
里面的属性 LinkButton
。
Now declare CommandName
and CommandArgument
properties inside LinkButton
.
<asp:LinkButton ID="lnkSomeLinkButton"
runat="server"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>"
CommandName ="SomeCommandName">LinkButtonText</asp:LinkButton>
现在,在.cs页面中,将事件处理程序写成......
Now, in .cs page, write the Event Handler like...
Sub ProductsGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
' If multiple buttons are used in a GridView control, use the
' CommandName property to determine which button was clicked.
If e.CommandName = "SomeCommandName" Then
' Convert the row index stored in the CommandArgument
' property to an Integer.
Dim index = Convert.ToInt32(e.CommandArgument)
' Retrieve the row that contains the button clicked
' by the user from the Rows collection.
Dim row = grdYourGridView.Rows(index)
Dim someBoundFieldValue As String = row.Cells(CellIndex).Text
End If
End Sub
GridViewRow clickedRow = ((LinkButton) sender).NamingContainer as GridViewRow;
Label lblID = (Label)clickedRow.FindControl("lblID");
为LinkButton附加Click事件,该事件放置在ItemTemplate中并访问行像
Attach a Click Event for the LinkButton which is placed in the ItemTemplate and access the Row like
protected void LinkButton1_Click(object sender, EventArgs e)
{
LinkButton lb = (LinkButton)sender;
GridViewRow row = (GridViewRow)lb.NamingContainer;
}
这篇关于如何从gridview中检索一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文