C# – Troubles retrieving data from within OnRowCommand from a GridViews

asp.netcdynamic-datagridview

If I have this <asp:ButtonField runat="server" DataTextField="Name" CommandName="GetName"></asp:ButonField> Within a GridView. Is there any way to retrieve the DataTextField (Name) from the OnRowCommand method?

<asp:GridView ID="GridView1" runat="server" 
 AllowPaging="True" AutoGenerateColumns="False" 
 DataSourceID="ObjectDataSource_Names" 
 DataKeyNames="ID,ModuleId" OnRowCommand="ChangeName"> 

Or alternatively, is there any way to make CommandName into an attribute where the command is dynamically entered based on given data, similar to the difference between DataTextField vs TextField.

Best Answer

I added <asp:BoundField DataField="Name" /> Then you can retrieve it using the same method here: GridView.onRowCommand Method

All I need to do now is find out a way to hide the field. If anyone knows how to, please let me know. Visible="false" gets rid of the field all together...

Related Topic