我有一个绑定到ObjectDataSource
(绑定到MySQL数据库)的ASP.NET GridView
。在这个网格上,我有2个未绑定的ButtonField
列,我想触发服务器端事件。因此,我在GridView
的RowCommand
事件中添加了一个事件处理程序方法。从ASP.NET GridView获取DataRow
在上述事件处理程序的代码中,我需要以某种方式获取用户点击的底层DataRow
。但是,我似乎无法得到这个工作;如果我使用类似于下面的代码的selectedRow
变量始终是null
:
protected void searchResultsGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
CallDataRow selectedRow = (CallDataRow) searchResultsGridView.Rows[Convert.ToInt32(e.CommandArgument)].DataItem;
}
我一派,发现如http://ranafaisal.wordpress.com/2008/03/31/how-to-get-the-current-row-in-gridview-row-command-event页,但没有我发现工作过。我敢肯定,我只是失去了一些东西很明显,但我想不出什么...
下面是ASP.NET代码是否有帮助:
<asp:GridView ID="searchResultsGridView" runat="server" AutoGenerateColumns="False"
DataKeyNames="PersonNo,CallDate"
Width="100%" AllowPaging="True" EnableSortingAndPagingCallbacks="True"
onrowcommand="searchResultsGridView_RowCommand" PageSize="20">
<Columns>
<asp:BoundField DataField="PersonNo" HeaderText="Account number" ReadOnly="True"
SortExpression="PersonNo" />
<asp:BoundField DataField="AgentNo" HeaderText="Agent number"
SortExpression="AgentNo" />
<asp:BoundField DataField="AgentName" HeaderText="Agent name"
SortExpression="AgentName" />
<asp:BoundField DataField="TelNumber" HeaderText="Telephone number"
SortExpression="TelNumber" />
<asp:BoundField DataField="CallDate" HeaderText="Call date/time" ReadOnly="True"
SortExpression="CallDate" />
<asp:ButtonField CommandName="play" HeaderText="Audio" ShowHeader="True"
Text="Play" />
<asp:ButtonField CommandName="download" Text="Download" />
</Columns>
</asp:GridView>
您是否尝试了其他解决方案而没有*** Hidden Fields ***? – Kiquenet 2016-06-29 12:01:03