All my drop down lists get reset to the first value when I go in to edit a record in the datagrid...

J

Josh Behl

I've got my datagrid working to the point where I can edit records and even
pick different values in my dropdownlists, save the record and have that
data committed to the table. The problem I am having is that when I go into
edit a record each of my picklist values get reset to the first value in the
list.


How can I fix this??

Josh Behl
 
C

cfaul

Josh Behl said:
I've got my datagrid working to the point where I can edit records and even
pick different values in my dropdownlists, save the record and have that
data committed to the table. The problem I am having is that when I go into
edit a record each of my picklist values get reset to the first value in the
list.


How can I fix this??

Josh Behl

Hi Josh

This is possibly happening because you dont have an 'isPostBack'
condition in your page_load sub. When you push the button to execute,
the page_load sub is called and your dropdownlists will be populated
again, using the first value of the list as the 'selected value'. This
can be fixed by putting the initial page loading code inside the
following if statement:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then
'Populate dropdownlist
End If

End Sub

Good luck
 
J

Josh Behl

I am currently populating my drop down lists with a collection of values
which I enter in the html code itself:
<asp:DropDownList id=ddlFee runat="server" Width="80px"
DataMember="OptionRequestCRM" DataSource="" DataTextField="Fee"
DataValueField="OptionID">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp....etc...

Since I am populating my drop down this way, is there another solution????
 
I

Imtiaz Hussain

You can databind the dropdownlist in the code behind file as well.
As charlene mentioned the data might be getting repopulated on postback.
You might want to prevent the datagrid that contains the dropdownlist from
rebinding on postback.

Hope this helps.
Imtiaz Hussain
 

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,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top