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

Discussion in 'ASP .Net Datagrid Control' started by Josh Behl, Oct 28, 2003.

  1. Josh Behl

    Josh Behl Guest

    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
     
    Josh Behl, Oct 28, 2003
    #1
    1. Advertising

  2. Josh Behl

    cfaul Guest

    "Josh Behl" <> wrote in message news:<#$>...
    > 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
     
    cfaul, Oct 28, 2003
    #2
    1. Advertising

  3. Josh Behl

    Josh Behl Guest

    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????


    "cfaul" <> wrote in message
    news:...
    > "Josh Behl" <> wrote in message

    news:<#$>...
    > > 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
     
    Josh Behl, Oct 28, 2003
    #3
  4. 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
     
    Imtiaz Hussain, Oct 29, 2003
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SirPoonga
    Replies:
    2
    Views:
    799
    Ben Strackany
    Jan 7, 2005
  2. Schultz
    Replies:
    3
    Views:
    576
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  3. weiwei
    Replies:
    0
    Views:
    1,047
    weiwei
    Jan 5, 2007
  4. jaysch
    Replies:
    0
    Views:
    1,258
    jaysch
    Apr 30, 2011
  5. Replies:
    0
    Views:
    182
Loading...

Share This Page