Retrieving the selected item from the dropdown list and storing it in a local variable

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

  1. Guest

    Hi,
    I used a dropdown control which is binded to a datagrid control. I
    passed the values to the dropdownlist from the database using a
    function as follows in the aspx itself.

    <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" />

    Oce the page is loaded all the values are added to the dropdown list.
    But when I thought of getting the selected value from the dropdown
    list, I am getting the following error while assigning the value to a
    local variable called Fldstr.

    DropDownList
    Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    string Fldstr=Fldlist.SelectedItem.Value;

    Here FieldType_add is the id of the dropdown list form which i am
    going to retrieve the selected value. Kindly help me to come out from
    this.


    Regards,
    Yasodhai
     
    , Mar 7, 2007
    #1
    1. Advertising

  2. What is the error?

    In any case, set a breakpoint on that line and check if all the properties
    you are using contain the values you are expecting.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    <> wrote in message
    news:...
    > Hi,
    > I used a dropdown control which is binded to a datagrid control. I
    > passed the values to the dropdownlist from the database using a
    > function as follows in the aspx itself.
    >
    > <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    > %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" />
    >
    > Oce the page is loaded all the values are added to the dropdown list.
    > But when I thought of getting the selected value from the dropdown
    > list, I am getting the following error while assigning the value to a
    > local variable called Fldstr.
    >
    > DropDownList
    > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    > string Fldstr=Fldlist.SelectedItem.Value;
    >
    > Here FieldType_add is the id of the dropdown list form which i am
    > going to retrieve the selected value. Kindly help me to come out from
    > this.
    >
    >
    > Regards,
    > Yasodhai
    >
     
    Eliyahu Goldin, Mar 7, 2007
    #2
    1. Advertising

  3. Guest

    hi,
    The error I am getting is as follows:

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

    Source Error:


    DropDownList
    Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    string Fldstr=Fldlist.SelectedItem.Value;
    Response.Write("Field Value is "+ Fldstr+" ");
    It throws the error in the second line while retrieving the selected
    value of the dropdown list and storing it in a variable called Fldstr.
    Kindly let me know how to come out from that.


    Regards,
    Yasodhai

    On Mar 7, 5:26 pm, "Eliyahu Goldin"
    <> wrote:
    > What is the error?
    >
    > In any case, set a breakpoint on that line and check if all the properties
    > you are using contain the values you are expecting.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    >
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > Hi,
    > > I used a dropdown control which is binded to a datagrid control. I
    > > passed the values to the dropdownlist from the database using a
    > > function as follows in the aspx itself.

    >
    > > <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    > > %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" />

    >
    > > Oce the page is loaded all the values are added to the dropdown list.
    > > But when I thought of getting the selected value from the dropdown
    > > list, I am getting the following error while assigning the value to a
    > > local variable called Fldstr.

    >
    > > DropDownList
    > > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    > > string Fldstr=Fldlist.SelectedItem.Value;

    >
    > > Here FieldType_add is the id of the dropdown list form which i am
    > > going to retrieve the selected value. Kindly help me to come out from
    > > this.

    >
    > > Regards,
    > > Yasodhai- Hide quoted text -

    >
    > - Show quoted text -
     
    , Mar 8, 2007
    #3
  4. Either Fldlist or Fldlist.SelectedItem is not set. Check in the debugger
    which of them is null.

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    <> wrote in message
    news:...
    > hi,
    > The error I am getting is as follows:
    >
    > Exception Details: System.NullReferenceException: Object reference not
    > set to an instance of an object.
    >
    > Source Error:
    >
    >
    > DropDownList
    > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    > string Fldstr=Fldlist.SelectedItem.Value;
    > Response.Write("Field Value is "+ Fldstr+" ");
    > It throws the error in the second line while retrieving the selected
    > value of the dropdown list and storing it in a variable called Fldstr.
    > Kindly let me know how to come out from that.
    >
    >
    > Regards,
    > Yasodhai
    >
    > On Mar 7, 5:26 pm, "Eliyahu Goldin"
    > <> wrote:
    >> What is the error?
    >>
    >> In any case, set a breakpoint on that line and check if all the
    >> properties
    >> you are using contain the values you are expecting.
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer & Consultant
    >> Microsoft MVP
    >> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    >>
    >> <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > Hi,
    >> > I used a dropdown control which is binded to a datagrid control. I
    >> > passed the values to the dropdownlist from the database using a
    >> > function as follows in the aspx itself.

    >>
    >> > <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    >> > %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" />

    >>
    >> > Oce the page is loaded all the values are added to the dropdown list.
    >> > But when I thought of getting the selected value from the dropdown
    >> > list, I am getting the following error while assigning the value to a
    >> > local variable called Fldstr.

    >>
    >> > DropDownList
    >> > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    >> > string Fldstr=Fldlist.SelectedItem.Value;

    >>
    >> > Here FieldType_add is the id of the dropdown list form which i am
    >> > going to retrieve the selected value. Kindly help me to come out from
    >> > this.

    >>
    >> > Regards,
    >> > Yasodhai- Hide quoted text -

    >>
    >> - Show quoted text -

    >
    >
     
    Eliyahu Goldin, Mar 8, 2007
    #4
  5. Guest

    Hi,
    As you said the Fldlist is null.

    <FooterTemplate>
    <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    %#GetFieldType()%>' DataTextField="Type" />
    </FooterTemplate>


    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;
    }

    private void DataGrid_Fields_ItemCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
    DropDownList
    Fldlist=(DropDownList)e.Item.FindControl("FldType_add");
    string Fldstr=Fldlist.SelectedItem.Value;
    Response.Write("Field Value is "+ Fldstr+" ");
    }

    Once the page gets loaded the dropdown list is filled with the values
    from the table "FieldType". While tyring to store the selected value
    from the list i am getting the error. Help me in this regard.

    Regards,
    Yasodhai



    On Mar 8, 1:37 pm, "Eliyahu Goldin"
    <> wrote:
    > Either Fldlist or Fldlist.SelectedItem is not set. Check in the debugger
    > which of them is null.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    >
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > hi,
    > > The error I am getting is as follows:

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

    >
    > > Source Error:

    >
    > > DropDownList
    > > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    > > string Fldstr=Fldlist.SelectedItem.Value;
    > > Response.Write("Field Value is "+ Fldstr+" ");
    > > It throws the error in the second line while retrieving the selected
    > > value of the dropdown list and storing it in a variable called Fldstr.
    > > Kindly let me know how to come out from that.

    >
    > > Regards,
    > > Yasodhai

    >
    > > On Mar 7, 5:26 pm, "Eliyahu Goldin"
    > > <> wrote:
    > >> What is the error?

    >
    > >> In any case, set a breakpoint on that line and check if all the
    > >> properties
    > >> you are using contain the values you are expecting.

    >
    > >> --
    > >> Eliyahu Goldin,
    > >> Software Developer & Consultant
    > >> Microsoft MVP
    > >> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

    >
    > >> <> wrote in message

    >
    > >>news:...

    >
    > >> > Hi,
    > >> > I used a dropdown control which is binded to a datagrid control. I
    > >> > passed the values to the dropdownlist from the database using a
    > >> > function as follows in the aspx itself.

    >
    > >> > <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    > >> > %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" />

    >
    > >> > Oce the page is loaded all the values are added to the dropdown list.
    > >> > But when I thought of getting the selected value from the dropdown
    > >> > list, I am getting the following error while assigning the value to a
    > >> > local variable called Fldstr.

    >
    > >> > DropDownList
    > >> > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    > >> > string Fldstr=Fldlist.SelectedItem.Value;

    >
    > >> > Here FieldType_add is the id of the dropdown list form which i am
    > >> > going to retrieve the selected value. Kindly help me to come out from
    > >> > this.

    >
    > >> > Regards,
    > >> > Yasodhai- Hide quoted text -

    >
    > >> - Show quoted text -- Hide quoted text -

    >
    > - Show quoted text -
     
    , Mar 8, 2007
    #5
  6. The FldType_add is not a part of the item. You can locate the footer in the
    datagrid's Controls collection.
    Look, for example, in this thread:

    http://groups.google.com/group/micr...st&q=datagrid footer&rnum=3#04fb18a7f436d8ba

    --
    Eliyahu Goldin,
    Software Developer & Consultant
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    <> wrote in message
    news:...
    > Hi,
    > As you said the Fldlist is null.
    >
    > <FooterTemplate>
    > <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    > %#GetFieldType()%>' DataTextField="Type" />
    > </FooterTemplate>
    >
    >
    > 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;
    > }
    >
    > private void DataGrid_Fields_ItemCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > {
    > DropDownList
    > Fldlist=(DropDownList)e.Item.FindControl("FldType_add");
    > string Fldstr=Fldlist.SelectedItem.Value;
    > Response.Write("Field Value is "+ Fldstr+" ");
    > }
    >
    > Once the page gets loaded the dropdown list is filled with the values
    > from the table "FieldType". While tyring to store the selected value
    > from the list i am getting the error. Help me in this regard.
    >
    > Regards,
    > Yasodhai
    >
    >
    >
    > On Mar 8, 1:37 pm, "Eliyahu Goldin"
    > <> wrote:
    >> Either Fldlist or Fldlist.SelectedItem is not set. Check in the debugger
    >> which of them is null.
    >>
    >> --
    >> Eliyahu Goldin,
    >> Software Developer & Consultant
    >> Microsoft MVP
    >> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    >>
    >> <> wrote in message
    >>
    >> news:...
    >>
    >>
    >>
    >> > hi,
    >> > The error I am getting is as follows:

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

    >>
    >> > Source Error:

    >>
    >> > DropDownList
    >> > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    >> > string Fldstr=Fldlist.SelectedItem.Value;
    >> > Response.Write("Field Value is "+ Fldstr+" ");
    >> > It throws the error in the second line while retrieving the selected
    >> > value of the dropdown list and storing it in a variable called Fldstr.
    >> > Kindly let me know how to come out from that.

    >>
    >> > Regards,
    >> > Yasodhai

    >>
    >> > On Mar 7, 5:26 pm, "Eliyahu Goldin"
    >> > <> wrote:
    >> >> What is the error?

    >>
    >> >> In any case, set a breakpoint on that line and check if all the
    >> >> properties
    >> >> you are using contain the values you are expecting.

    >>
    >> >> --
    >> >> Eliyahu Goldin,
    >> >> Software Developer & Consultant
    >> >> Microsoft MVP
    >> >> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

    >>
    >> >> <> wrote in message

    >>
    >> >>news:...

    >>
    >> >> > Hi,
    >> >> > I used a dropdown control which is binded to a datagrid control. I
    >> >> > passed the values to the dropdownlist from the database using a
    >> >> > function as follows in the aspx itself.

    >>
    >> >> > <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    >> >> > %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" />

    >>
    >> >> > Oce the page is loaded all the values are added to the dropdown
    >> >> > list.
    >> >> > But when I thought of getting the selected value from the dropdown
    >> >> > list, I am getting the following error while assigning the value to
    >> >> > a
    >> >> > local variable called Fldstr.

    >>
    >> >> > DropDownList
    >> >> > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    >> >> > string Fldstr=Fldlist.SelectedItem.Value;

    >>
    >> >> > Here FieldType_add is the id of the dropdown list form which i am
    >> >> > going to retrieve the selected value. Kindly help me to come out
    >> >> > from
    >> >> > this.

    >>
    >> >> > Regards,
    >> >> > Yasodhai- Hide quoted text -

    >>
    >> >> - Show quoted text -- Hide quoted text -

    >>
    >> - Show quoted text -

    >
    >
     
    Eliyahu Goldin, Mar 8, 2007
    #6
  7. Guest

    Hi,
    Its working fine. Thanks a lot. I retrieved the values....


    Regards,
    Yasodhai

    On Mar 8, 3:01 pm, "Eliyahu Goldin"
    <> wrote:
    > The FldType_add is not a part of the item. You can locate the footer in the
    > datagrid's Controls collection.
    > Look, for example, in this thread:
    >
    > http://groups.google.com/group/microsoft.public.dotnet.framework.aspn...
    >
    > --
    > Eliyahu Goldin,
    > Software Developer & Consultant
    > Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    >
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > Hi,
    > > As you said the Fldlist is null.

    >
    > > <FooterTemplate>
    > > <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    > > %#GetFieldType()%>' DataTextField="Type" />
    > > </FooterTemplate>

    >
    > > 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;
    > > }

    >
    > > private void DataGrid_Fields_ItemCommand(object source,
    > > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    > > {
    > > DropDownList
    > > Fldlist=(DropDownList)e.Item.FindControl("FldType_add");
    > > string Fldstr=Fldlist.SelectedItem.Value;
    > > Response.Write("Field Value is "+ Fldstr+" ");
    > > }

    >
    > > Once the page gets loaded the dropdown list is filled with the values
    > > from the table "FieldType". While tyring to store the selected value
    > > from the list i am getting the error. Help me in this regard.

    >
    > > Regards,
    > > Yasodhai

    >
    > > On Mar 8, 1:37 pm, "Eliyahu Goldin"
    > > <> wrote:
    > >> Either Fldlist or Fldlist.SelectedItem is not set. Check in the debugger
    > >> which of them is null.

    >
    > >> --
    > >> Eliyahu Goldin,
    > >> Software Developer & Consultant
    > >> Microsoft MVP
    > >> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

    >
    > >> <> wrote in message

    >
    > >>news:...

    >
    > >> > hi,
    > >> > The error I am getting is as follows:

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

    >
    > >> > Source Error:

    >
    > >> > DropDownList
    > >> > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    > >> > string Fldstr=Fldlist.SelectedItem.Value;
    > >> > Response.Write("Field Value is "+ Fldstr+" ");
    > >> > It throws the error in the second line while retrieving the selected
    > >> > value of the dropdown list and storing it in a variable called Fldstr.
    > >> > Kindly let me know how to come out from that.

    >
    > >> > Regards,
    > >> > Yasodhai

    >
    > >> > On Mar 7, 5:26 pm, "Eliyahu Goldin"
    > >> > <> wrote:
    > >> >> What is the error?

    >
    > >> >> In any case, set a breakpoint on that line and check if all the
    > >> >> properties
    > >> >> you are using contain the values you are expecting.

    >
    > >> >> --
    > >> >> Eliyahu Goldin,
    > >> >> Software Developer & Consultant
    > >> >> Microsoft MVP
    > >> >> [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

    >
    > >> >> <> wrote in message

    >
    > >> >>news:...

    >
    > >> >> > Hi,
    > >> >> > I used a dropdown control which is binded to a datagrid control. I
    > >> >> > passed the values to the dropdownlist from the database using a
    > >> >> > function as follows in the aspx itself.

    >
    > >> >> > <asp:DropDownList ID="FldType_add" Runat="server" DataSource='<
    > >> >> > %#GetFieldType()%>' DataValueField="Type" DataTextField="Type" />

    >
    > >> >> > Oce the page is loaded all the values are added to the dropdown
    > >> >> > list.
    > >> >> > But when I thought of getting the selected value from the dropdown
    > >> >> > list, I am getting the following error while assigning the value to
    > >> >> > a
    > >> >> > local variable called Fldstr.

    >
    > >> >> > DropDownList
    > >> >> > Fldlist=(DropDownList)e.Item.FindControl("FieldType_add");
    > >> >> > string Fldstr=Fldlist.SelectedItem.Value;

    >
    > >> >> > Here FieldType_add is the id of the dropdown list form which i am
    > >> >> > going to retrieve the selected value. Kindly help me to come out
    > >> >> > from
    > >> >> > this.

    >
    > >> >> > Regards,
    > >> >> > Yasodhai- Hide quoted text -

    >
    > >> >> - Show quoted text -- Hide quoted text -

    >
    > >> - Show quoted text -- Hide quoted text -

    >
    > - Show quoted text -
     
    , Mar 8, 2007
    #7
    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. rohith
    Replies:
    3
    Views:
    6,026
    rohith
    Aug 29, 2003
  2. Kris Rockwell

    DropDown List Default Selected Item

    Kris Rockwell, Apr 11, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    27,907
    Dan Brussee
    Apr 12, 2004
  3. Replies:
    2
    Views:
    511
  4. Replies:
    0
    Views:
    758
  5. SSP

    dropdown list does not change selected item?

    SSP, Oct 29, 2003, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    1,221
Loading...

Share This Page