Hello,
I want populate or bind DropDownList selected value in GridView EditItemTemplate in asp.net using c#
On my code below I have this error
Server Error in '/aspnet' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution
of the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 92: catch (Exception ex)
Line 93: {
Line 94: throw ex;
Line 95: }
Line 96: finally
Any suggestion? Please help me.
using (MySqlConnection cn =
new MySqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
using (MySqlCommand cmd =
new MySqlCommand(sql, cn))
{
try
{
ddlprf.DataSource = cmd.ExecuteReader();
ddlprf.DataTextField = "User_level";
ddlprf.DataValueField = "User_level";
ddlprf.DataBind();
ddlprf.Items.Insert(0, new ListItem("=== === ===", ""));;
HiddenField hdnprf = (HiddenField)e.Row.FindControl("hdnprf");
ddlprf.Items.FindByValue(hdnprf.Value).Selected = true;
if (ddlprf.Items.Count > 1)
{
ddlprf.Enabled = true;
}
else
{
ddlprf.Enabled = false;
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
cmd.Connection.Close();
}
}
}