Problem with retrieving the selected value in a dropdown list

Y

yasodhai

Hi,
I used a dropdown control bind to a datagrid.
<EditItemTemplate>
<asp:DropDownList 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
 
G

Guest

Hi,
I used a dropdown control bind to a datagrid.
<EditItemTemplate>
<asp:DropDownList 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
 
Y

yasodhai

ok. Thanks a lot.

Regards,
Yasodhai

"FldType_edit" != "FieldType_edit"

You named your control as FldType_edit- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,525
Members
44,997
Latest member
mileyka

Latest Threads

Top