Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

Can I set a DetaiView control's datasource at runtime?

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.
ASKER CERTIFIED SOLUTION
Avatar of yogsoft
yogsoft
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Opps.  I should be
"~/Item/ItemDetail.aspx?ItemId=" + itemId

Open in new window


Sorry
I guess not getting the strong coffee this morning was a bad idea.  You want to save the itemId as an int probably and then convert it to a string when you add it to the end of the URL.  Then, when you pull it back out of the Query String, you can convert it back to an int.

Hopefully I am leading you where you were looking!!!
Avatar of lapucca
lapucca

ASKER

It doesn't matter I put it in the url as parm or store in session my question here is setting the datasourde for the viewdetail control.  I created a sqldatasource control at page_load event.  Anyway, please read over again my question.  Thank you.