well if your details view has a textbox or label that is holding the value (item ID) you can use Findcontrol in your detailsview to find the control and get the value from its TEXT property.
something like this :
//find the code from a textbox
string myId = "";
TextBox tbTmp = (TextBox)myDetailsView.FindControl("mytextbox");
if(tbTmp != null){
myId = tbTmp.Text;
}
now that may not find the textbox (depends on how your child controls are set) so you may need something like :
My DetailsView doesn't display the ID that I need at all and I don't want to start adding hidden controls to the DetailsView. Also I imagine that FindControl is actually interating throughevery single control to find the one I want.
I'm really after getting access to the underlying datasource. But when I look at the DataSource property it seems to be Nothing.
elziko
Member
1 Points
17 Posts
ItemDetail Page
Dec 21, 2007 03:10 PM|LINK
In server-side code I want to be able to get at some of the data loaded into the DetailsView component. Specifically the item ID of the loaded item.
I have looked through all the members of the DetailsView component but can't seem to work out what I need to do.
Any help would be much appreciated.
TIA
mcmcomasp
Contributor
6834 Points
1436 Posts
Re: ItemDetail Page
Dec 21, 2007 05:24 PM|LINK
well if your details view has a textbox or label that is holding the value (item ID) you can use Findcontrol in your detailsview to find the control and get the value from its TEXT property.
something like this :
//find the code from a textbox
string myId = "";
TextBox tbTmp = (TextBox)myDetailsView.FindControl("mytextbox");
if(tbTmp != null){
myId = tbTmp.Text;
}
now that may not find the textbox (depends on how your child controls are set) so you may need something like :
string myId = "";
TextBox tbTmp = (TextBox)myDetailsView.Controls[0].FindControl("mytextbox");
if(tbTmp != null){
myId = tbTmp.Text;
}
hth,
mcm
elziko
Member
1 Points
17 Posts
Re: ItemDetail Page
Dec 22, 2007 08:31 AM|LINK
Thanks for the reply.
My DetailsView doesn't display the ID that I need at all and I don't want to start adding hidden controls to the DetailsView. Also I imagine that FindControl is actually interating throughevery single control to find the one I want.
I'm really after getting access to the underlying datasource. But when I look at the DataSource property it seems to be Nothing.