Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Problem with retrieving the selected value in a dropdown list

Reply
Thread Tools

Problem with retrieving the selected value in a dropdown list

 
 
yasodhai@gmail.com
Guest
Posts: n/a
 
      03-09-2007
Hi,
I used a dropdown control bind to a datagrid.
<EditItemTemplate>
<aspropDownList 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

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      03-09-2007
On Mar 9, 10:22 am, yasod...@gmail.com wrote:
> Hi,
> I used a dropdown control bind to a datagrid.
> <EditItemTemplate>
> <aspropDownList 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

 
Reply With Quote
 
 
 
 
yasodhai@gmail.com
Guest
Posts: n/a
 
      03-09-2007
ok. Thanks a lot.

Regards,
Yasodhai

On Mar 9, 5:49 pm, "Alexey Smirnov" <alexey.smir...@gmail.com> wrote:
> On Mar 9, 10:22 am, yasod...@gmail.com wrote:
>
>
>
>
>
> > Hi,
> > I used a dropdown control bind to a datagrid.
> > <EditItemTemplate>
> > <aspropDownList 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 -



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get selected value from dropdown list Andy Sutorius ASP .Net 6 10-29-2012 08:14 PM
Problem with retrieving the selected value in a dropdown list yasodhai@gmail.com ASP .Net Datagrid Control 0 03-09-2007 07:16 AM
Retrieving the selected item from the dropdown list and storing it in a local variable yasodhai@gmail.com ASP .Net 6 03-08-2007 11:52 AM
bind a dropdown in a column in a datagrid based on the dropdown value selected in another column of the datagrid. vishnu ASP .Net 1 03-25-2006 01:24 PM
Re: need selected value from dropdown list box Scott Allen ASP .Net 1 08-25-2004 07:09 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57