Last post Nov 19, 2008 05:45 PM by LastManStanding
Nov 14, 2008 08:36 PM|LastManStanding|LINK
I have a nested GridView controller inside a DataList.
In the OnItemDataBound control I'm trying to specify the DataSource for gridview but it is not available. How can I resolve this?
protected void objDataList_OnItemDataBound(object sender, DataListItemEventArgs e)
(GridView)e.Item.FindControl("objGridView").DataSource = objDataTable; //this does not work
Nov 14, 2008 11:22 PM|LastManStanding|LINK
I don't understand why but this is a solution, can someone explain this to me. It seems like binding the temporary GridView effects the original, which initially gets assigned to the temporary.
GridView objGridViewTemp = new GridView();
objGridViewTemp = (GridView)e.Item.FindControl("objGridView");
objGridViewTemp.DataSource = objDataTable;
Nov 19, 2008 06:40 AM|Qin Dian Tang - MSFT|LINK
In your original post you can do it like this:
((GridView)e.Item.FindControl("objGridView")).DataSource = objDataTable;
You forgot the bracket "()".
Nov 19, 2008 05:45 PM|LastManStanding|LINK
Thanks for your response. the extra "()" brackets do not expose the DataSource property. However, for controls such as a HTMLHiddenField, they work, when I do the extra () I can access value.