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

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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.aspnet.datagridcontrol/browse_frm/thread/8000264c648b3179/04fb18a7f436d8ba?lnk=st&q=datagrid++footer&rnum=3#04fb18a7f436d8ba

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


<yasodhai@xxxxxxxxx> wrote in message
news:1173345697.323011.187710@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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...@xxxxxxxxxxxx> 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

<yasod...@xxxxxxxxx> wrote in message

news:1173339187.450811.233140@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx



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"
<REMOVEALLCAPITALSeEgGoldD...@xxxxxxxxxxxx> 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

<yasod...@xxxxxxxxx> wrote in message

news:1173257496.153708.190680@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

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 -




.



Relevant Pages

  • Re: Transfer data from one Content Control to another Word 2007 VB
    ... Dim cc1PtMedication As ContentControl ... incorporates a dropdown list. ... you can just assign the text of one control directly to the text ... macro transfers the contents of room 1 to the controls for room 3, ...
    (microsoft.public.word.vba.beginners)
  • Re: Create control with drop-down similar to ComboBox
    ... problem (more or less I am changing the control size on dropdown, ... a parent large enough to hold the entire dropdown). ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... private void button1_Click ...
    (microsoft.public.dotnet.framework.windowsforms)
  • Re: Data List Insert new problem
    ... Microsoft MSDN Online Support Lead ... I try this solution but it dosen't seems to work so I changed the dropdown ... So for the control display the color lists you selected from database, ... Now when I'm selecting let say GN_ID 35 in the the drop down ...
    (microsoft.public.dotnet.framework.aspnet)
  • ViewsState, DropDownList and WebControl
    ... This class Load an ASCX control (that contains other controls in itself like ... DataBindand if it's not postback, ... Tengo una clase que hereda de WebControl ... pero el dropdown me sale completamente vacio. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: DropDownList problem
    ... I am trying to develop a composite control. ... When I pick a value in a a DropDown I want to apply some RowFilter to my ... private DropDownList drAttrAdditional = new DropDownList; ... protected override void CreateChildControls() ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)