Forum Moderators: open
//if option exists show it, otherwise put N/A in DropDownList
SqlDataReader ddDR4 = null;
SqlCommand sql4 = new SqlCommand("SELECT DISTINCT options FROM hwproducts WHERE options IS NOT NULL AND style='" + pstyle + "'", MyConnection);
MyConnection.Open();
ddDR4 = sql4.ExecuteReader(CommandBehavior.CloseConnection);
DropDownListOption1.DataSource = ddDR4;
DropDownListOption1.DataTextField = "options";
DropDownListOption1.DataValueField = "options";
DropDownListOption1.DataBind();
MyConnection.Close();
...
MyConnection.Close();
if (!ddDR4.HasRows)
{
DropDownListOption1.Items.Clear();
ListItem li = new ListItem("N/A");
DropDownListOption1.Items.Add(li);
}
//if option exists show it, otherwise put N/A in DropDownList
SqlDataReader ddDR4 = null;
SqlCommand sql4 = new SqlCommand("SELECT DISTINCT options FROM hwproducts WHERE options IS NOT NULL AND style='" + pstyle + "'", MyConnection);
MyConnection.Open();
ddDR4 = sql4.ExecuteReader(CommandBehavior.CloseConnection);
if (!ddDR4.HasRows)
{
DropDownListOption1.Items.Clear();
ListItem li = new ListItem("N/A");
DropDownListOption1.Items.Add(li);
}
else
{
DropDownListOption1.DataSource = ddDR4;
DropDownListOption1.DataTextField = "options";
DropDownListOption1.DataValueField = "options";
DropDownListOption1.DataBind();
}
MyConnection.Close();