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
 

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

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top