Problem with retrieving the selected value in a dropdown list

Discussion in 'ASP .Net' started by yasodhai@gmail.com, Mar 9, 2007.

  1. Guest

    Hi,
    I used a dropdown control bind to a datagrid.
    <EditItemTemplate>
    <asp:DropDownList ID="FldType_edit" Runat="server" DataSource='<
    %#GetFieldType()%>' DataTextField="Type" />
    </EditItemTemplate>

    The values for the datagrid are retrieved from the database using the
    GetFieldType function


    public DataSet GetFieldType()
    {
    SqlDataAdapter fldad = new SqlDataAdapter("SELECT
    Type
    FROM FieldType Order by FID", myConnection);
    DataSet fldds = new DataSet();
    fldad.Fill(fldds,"FieldType");
    return fldds;



    }


    Then i try to retrieve the selected the values in the database. i
    thought of doing this in the update command event.

    public void DataGrid_Fields_UpdateCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    if (e.Item.ItemType == ListItemType.EditItem)
    {
    DropDownList dd;
    dd = (DropDownList)e.Item.FindControl("FieldType_edit");
    string fldval=dd.SelectedItem.Value;
    Response.Write("Field Value is "+ fldval+" ");
    }



    }


    While executing this i am getting the following error:

    System.NullReferenceException: Object reference not set to an
    instance
    of an object.


    While debugging, i found the value of dd is "Unexpected value". The
    value is not assigned for dd. Kindly help me to come out from that.


    Thanks & Regards,
    Yasodhai
     
    , Mar 9, 2007
    #1
    1. Advertising

  2. On Mar 9, 10:22 am, wrote:
    > Hi,
    > I used a dropdown control bind to a datagrid.
    > <EditItemTemplate>
    > <asp:DropDownList ID="FldType_edit" Runat="server" DataSource='<
    > %#GetFieldType()%>' DataTextField="Type" />
    > </EditItemTemplate>
    >
    > The values for the datagrid are retrieved from the database using the
    > GetFieldType function
    >
    > public DataSet GetFieldType()
    > {
    > SqlDataAdapter fldad = new SqlDataAdapter("SELECT
    > Type
    > FROM FieldType Order by FID", myConnection);
    > DataSet fldds = new DataSet();
    > fldad.Fill(fldds,"FieldType");
    > return fldds;
    >
    > }
    >
    > Then i try to retrieve the selected the values in the database. i
    > thought of doing this in the update command event.
    >
    > public void DataGrid_Fields_UpdateCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > {
    > if (e.Item.ItemType == ListItemType.EditItem)
    > {
    > DropDownList dd;
    > dd = (DropDownList)e.Item.FindControl("FieldType_edit");
    > string fldval=dd.SelectedItem.Value;
    > Response.Write("Field Value is "+ fldval+" ");
    > }
    >
    > }
    >
    > While executing this i am getting the following error:
    >
    > System.NullReferenceException: Object reference not set to an
    > instance
    > of an object.
    >
    > While debugging, i found the value of dd is "Unexpected value". The
    > value is not assigned for dd. Kindly help me to come out from that.
    >
    > Thanks & Regards,
    > Yasodhai


    "FldType_edit" != "FieldType_edit"

    You named your control as FldType_edit
     
    Alexey Smirnov, Mar 9, 2007
    #2
    1. Advertising

  3. Guest

    ok. Thanks a lot.

    Regards,
    Yasodhai

    On Mar 9, 5:49 pm, "Alexey Smirnov" <> wrote:
    > On Mar 9, 10:22 am, wrote:
    >
    >
    >
    >
    >
    > > Hi,
    > > I used a dropdown control bind to a datagrid.
    > > <EditItemTemplate>
    > > <asp:DropDownList ID="FldType_edit" Runat="server" DataSource='<
    > > %#GetFieldType()%>' DataTextField="Type" />
    > > </EditItemTemplate>

    >
    > > The values for the datagrid are retrieved from the database using the
    > > GetFieldType function

    >
    > > public DataSet GetFieldType()
    > > {
    > > SqlDataAdapter fldad = new SqlDataAdapter("SELECT
    > > Type
    > > FROM FieldType Order by FID", myConnection);
    > > DataSet fldds = new DataSet();
    > > fldad.Fill(fldds,"FieldType");
    > > return fldds;

    >
    > > }

    >
    > > Then i try to retrieve the selected the values in the database. i
    > > thought of doing this in the update command event.

    >
    > > public void DataGrid_Fields_UpdateCommand(object source,
    > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > {
    > > if (e.Item.ItemType == ListItemType.EditItem)
    > > {
    > > DropDownList dd;
    > > dd = (DropDownList)e.Item.FindControl("FieldType_edit");
    > > string fldval=dd.SelectedItem.Value;
    > > Response.Write("Field Value is "+ fldval+" ");
    > > }

    >
    > > }

    >
    > > While executing this i am getting the following error:

    >
    > > System.NullReferenceException: Object reference not set to an
    > > instance
    > > of an object.

    >
    > > While debugging, i found the value of dd is "Unexpected value". The
    > > value is not assigned for dd. Kindly help me to come out from that.

    >
    > > Thanks & Regards,
    > > Yasodhai

    >
    > "FldType_edit" != "FieldType_edit"
    >
    > You named your control as FldType_edit- Hide quoted text -
    >
    > - Show quoted text -
     
    , Mar 9, 2007
    #3
    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. Scott Allen
    Replies:
    1
    Views:
    881
    Scott Allen
    Aug 25, 2004
  2. Andy Sutorius

    how to get selected value from dropdown list

    Andy Sutorius, Mar 15, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    82,641
    raouf2me
    Oct 29, 2012
  3. vishnu
    Replies:
    1
    Views:
    1,242
    Patrick.O.Ige
    Mar 25, 2006
  4. Replies:
    6
    Views:
    608
  5. Replies:
    0
    Views:
    756
Loading...

Share This Page