DetailsView template field problem

G

Guest

I'm using detailsview control with a template field which contains a
dropdownlist
I databind the dropdownlist during page load, now the problem is
dropdownlist loses state during postbacks, i looked at the enableviewstate
property to see if viewstate is enabled and it is.

Any ideas!!!

Thanks,
<Ram/>
 
G

Guest

It depends on which control/event caused the postback. If you have the
dropdownlist within an EditItemTemplate then you can get its value during the
processing of the ItemUpdated that is triggered by the DetailsView like this:

void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
DropDownList ddl =
(DropDownList)((System.Web.UI.WebControls.DetailsView)sender).FindControl("DropDownList1");
if (ddl != null) //you found the dropdownlist
{
//add your code here
}
}
 
B

Bart Waeterschoot

Hi Ram,

You should add a check in your page load method for a postback:

if(!IsPostBack)
{
//Bind your data
}

If you don't do this, your ViewState will be reïnitialized during
every page load.

Also make sure that you have unique values in your dropdownlist or it
will return false data from the viewstate.

Regards,
Bart
 
Joined
Jun 7, 2008
Messages
1
Reaction score
0
I am facing a similar problem with a DropDownList in an EditItemTemplate in a DetailsView field row. I use the Load event of the DropDownList to bind its values. I have two such rows one after another. For one, it works as planned. For the other, the Load event does not fire the first time the DetailsView go into Edit mode. Only if I click something else on the page and there is a page refresh does the Load event get triggered.

Is there a bug somewhere? How do I get around this?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top