Passing Hidden Boundfield to Nested GridView using DataKeyNames
Posted on 2013-10-22
I have a hidden boundfield that is in a parent GridView
<asp:BoundField DataField="Name" HeaderText="Name" ReadOnly="true"
SortExpression="Name" Visible="false" />
I would like to use DataKeyNames
On the script side I am using this code example to pass what I need from GridView1 to GridView2
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
if (e.Row.RowType == DataControlRowType.DataRow)
SqlDataSource s = (SqlDataSource)e.Row.FindControl("GridView2");
s.SelectParameters.DefaultValue = e.Row.Cells.Text;
It works fine if I make the "Name" value visible but as soon as I hide, it doesnt work.
I understand that that the script code (example from MSDN site) will not pull from the DataKeyName but pulls from the first boundfield. How can I use the DataKeyName in the same way to get this to work? Also from looking at other questions I can't have the Name value converted to an int as it errors.