bertmn
asked on
Passing Hidden Boundfield to Nested GridView using DataKeyNames
Hi,
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
DataKeyNames="Name"
On the script side I am using this code example to pass what I need from GridView1 to GridView2
protected void GridView1_RowDataBound(obj ect sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow )
{
SqlDataSource s = (SqlDataSource)e.Row.FindC ontrol("Gr idView2");
s.SelectParameters[0].Defa ultValue = e.Row.Cells[0].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.
TIA
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
DataKeyNames="Name"
On the script side I am using this code example to pass what I need from GridView1 to GridView2
protected void GridView1_RowDataBound(obj
{
if (e.Row.RowType == DataControlRowType.DataRow
{
SqlDataSource s = (SqlDataSource)e.Row.FindC
s.SelectParameters[0].Defa
}
}
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.
TIA
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The reference material had some errors, but ultimately worked after some trial and error.
ASKER
Using the reference you posted I was able to sort of get things working.
If I use this code
Open in new window
It works but it offsets the data by 1. So parent row 1 gets no child data while parent row 2 gets the child data that should go into parent row 1 and so on.
If I use this code
Open in new window
I get the error: CS0165: Use of unassigned local variable 'gvrow'
I used the reference material from this link you posted.
http://www.aspdotnet-suresh.com/2012/06/get-multiple-datakeyname-values-from.html
It had the best reference.
Edit. I am using two DataKeys my original question I had only posted for one DataKey.
TIA