Dropdownlist is empty
-
I have the following code but on form load my dropdownlist is empty even though there are Items present in the database.I am trying to populate the Item Ids in the dropdownlist.but it is getting populated as empty. if (!Page.IsPostBack) { //code to populate dropdown ddlItems.DataSource = objDS1; ddlItems.DataMember = objDS1.Tables["Items"].ToString(); ddlItems.DataTextField = "Name"; ddlItems.DataValueField = "Id"; ddlItems.DataBind(); } Riz
-
I have the following code but on form load my dropdownlist is empty even though there are Items present in the database.I am trying to populate the Item Ids in the dropdownlist.but it is getting populated as empty. if (!Page.IsPostBack) { //code to populate dropdown ddlItems.DataSource = objDS1; ddlItems.DataMember = objDS1.Tables["Items"].ToString(); ddlItems.DataTextField = "Name"; ddlItems.DataValueField = "Id"; ddlItems.DataBind(); } Riz
objDS1.Tables["Items"].ToString()
will probably returns a string like "System.Data.DataTable, System.Data". Whereas what you want is the NAME of the table to use as datamamber. So changeddlItems.DataMember = objDS1.Tables["Items"].ToString();
toddlItems.DataMember = "Items";
-
objDS1.Tables["Items"].ToString()
will probably returns a string like "System.Data.DataTable, System.Data". Whereas what you want is the NAME of the table to use as datamamber. So changeddlItems.DataMember = objDS1.Tables["Items"].ToString();
toddlItems.DataMember = "Items";
-
I have the following code but on form load my dropdownlist is empty even though there are Items present in the database.I am trying to populate the Item Ids in the dropdownlist.but it is getting populated as empty. if (!Page.IsPostBack) { //code to populate dropdown ddlItems.DataSource = objDS1; ddlItems.DataMember = objDS1.Tables["Items"].ToString(); ddlItems.DataTextField = "Name"; ddlItems.DataValueField = "Id"; ddlItems.DataBind(); } Riz
Verify that
objDS1
actually contains data. I know you said the database table contains items, but perhaps there's a mistake in the code that populatesobjDS1
? Perhaps turn tracing on, and usePage.Trace.Write
to inspect yourobjDS1
object. Or just throw in something likeResponse.Write(objDS1.Tables["Items"].Rows.Count);
after your code that populatesobjDS1
just to make sure it has rows. -
I changed it the way u've said but still the dropdownlist is empty.Is there any other way to do it? Plz let me knw. Riz
Maybe change to dropDownList.DataSource = yourDataSet.Tables[0].DefaultView; will helps... xedom developers team personal web page
-
I have the following code but on form load my dropdownlist is empty even though there are Items present in the database.I am trying to populate the Item Ids in the dropdownlist.but it is getting populated as empty. if (!Page.IsPostBack) { //code to populate dropdown ddlItems.DataSource = objDS1; ddlItems.DataMember = objDS1.Tables["Items"].ToString(); ddlItems.DataTextField = "Name"; ddlItems.DataValueField = "Id"; ddlItems.DataBind(); } Riz