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
 

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

Top