Can I set a DetaiView control's datasource at runtime?
Posted on 2011-09-30
Hi, i'm using asp.net 3.5 and C#.
I have a web page where I display all items in a gridview control whose Auto-generate Select is enabled. When a user selects a row(item), I save the item id in session using the Gridview control's Select event. After the user selects an item and then select Detail in the menu bar, this will take them to the item's detail page where I have a DetailView control.
I create a sqldatabase in the Page_load event when it's !IsPostBack. Because I have to get the itemid from the session variable so i can only do this at runtime. Is this the best way to do this? I get a runtime error about I didn't set the datakey field. but when I tried to do this in backend code I get tooltip that his field is read only and not for assignment. What am I doing wrong here? Thank you.