472,363 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,363 software developers and data experts.

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 5717
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: asd | last post by:
I need to find the value/index of the previously selected item of a select list. That is, when the user selects an item from the list and a certain condition elsewhere in the form is not met, I...
5
by: Kris Rockwell | last post by:
Hello (again), I have gotten the dropdown list functionality to work through a few tricks (probably not the most efficient, but it works) but I am not sure how to set the default selected value....
2
by: tmeister | last post by:
I must be missing something obvious. I have a drop down list in asp.net and it populates the states from a database. When I view the source of the page I get the standard option tags with the...
6
by: Jenna Alten | last post by:
I have a datagrid with a template column that contains a dropdown list. I currently fill and display the dropdown list on the page load. This is working correctly. I am NOT using an Edit Column. I...
2
by: John | last post by:
I have a listbox that is databound when my form loads. A user can then select and option using a drop down box. When the user selects an option the corresponding items in the listbox gets selected....
1
by: Ben | last post by:
I have a formview with a few dropdownlists (software version, database version, etc). When a software version is selected, the database version dropdownlist updates itself accordingly. When in...
2
by: echan8 | last post by:
I have a dropdown list in a datagrid which I am dynamically adding items to with JavaScript. When I try to access the value of the dropdown list on postback, there is no value. The value is...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
2
by: yasodhai | last post by:
Hi, I used a dropdown control bind to a datagrid. <EditItemTemplate> <asp:DropDownList ID="FldType_edit" Runat="server" DataSource='< %#GetFieldType()%>' DataTextField="Type" />...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
0
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.