469,950 Members | 1,381 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

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

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("FieldTyp e_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 '07 #1
6 5596
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
<ya******@gmail.comwrote in message
news:11**********************@s48g2000cws.googlegr oups.com...
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("FieldTyp e_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 '07 #2
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("FieldTyp e_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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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

<yasod...@gmail.comwrote in message

news:11**********************@s48g2000cws.googlegr oups.com...
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("FieldTyp e_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 '07 #3
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
<ya******@gmail.comwrote in message
news:11**********************@j27g2000cwj.googlegr oups.com...
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("FieldTyp e_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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>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

<yasod...@gmail.comwrote in message

news:11**********************@s48g2000cws.googleg roups.com...
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("FieldTyp e_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 '07 #4
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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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

<yasod...@gmail.comwrote in message

news:11**********************@j27g2000cwj.googlegr oups.com...
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("FieldTyp e_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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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
<yasod...@gmail.comwrote in message
>news:11**********************@s48g2000cws.googleg roups.com...
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("FieldTyp e_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 '07 #5
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/micro...fb18a7f436d8ba

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
<ya******@gmail.comwrote in message
news:11**********************@t69g2000cwt.googlegr oups.com...
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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
>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

<yasod...@gmail.comwrote in message

news:11**********************@j27g2000cwj.googleg roups.com...
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("FieldTyp e_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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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
><yasod...@gmail.comwrote in message
>>news:11**********************@s48g2000cws.google groups.com...
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("FieldTyp e_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 '07 #6
Hi,
Its working fine. Thanks a lot. I retrieved the values....
Regards,
Yasodhai

On Mar 8, 3:01 pm, "Eliyahu Goldin"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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/micro...framework.aspn...

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

<yasod...@gmail.comwrote in message

news:11**********************@t69g2000cwt.googlegr oups.com...
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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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
<yasod...@gmail.comwrote in message
>news:11**********************@j27g2000cwj.googleg roups.com...
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("FieldTyp e_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"
<REMOVEALLCAPITALSeEgGoldD...@mMvVpPsS.orgwrote:
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
<yasod...@gmail.comwrote in message
>news:11**********************@s48g2000cws.googleg roups.com...
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("FieldTyp e_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 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Kris Rockwell | last post: by
2 posts views Thread by tmeister | last post: by
2 posts views Thread by John | last post: by
11 posts views Thread by Santosh | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.