How to get dynamic value in dropdownlist in asp.net?

How to get value of menu type in C# code?

I try and got solution is below:

Just add the below code into your particular page.


public static void dropdownbind1(string strtbl, string field, DropDownList dl, string dttext, string dtvale)
{
dl.Items.Clear();
str = "select distinct " + field + " from " + strtbl + ""
cmd = new MySqlCommand(str, Classmysql.con);
dtp = new MySqlDataAdapter(cmd);
ds = new DataSet();
dtp.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
dl.DataSource = ds;
dl.DataTextField = dttext;
dl.DataValueField = dtvale;
dl.DataBind();
dl.Items.Insert(0, "SELECT");
}
else
{
dl.Items.Insert(0, "no details");

}
here is the example.it is general method.

}

Your problem has been solve.

About the Author

avatar