Hi,
I have a datatable dt. Within this datatable are numerous fields including 'Name' and 'ID'. Neither fields are unique.
I want to bind this datatable to my dropdownlist ddlExample, only displaying unique 'Name' values. I want the 'ID' field to be the value of the drop down list.
Can this be done?
So far, I've got the following:
var query = (from row in dt select row.Name).Distinct();
ddlExample.DataSource = query;
ddlExample.DataValueField = null;
ddlExample.DataTextField = null;
ddlExample.DataBind();
which returns unique 'Name' values, but I cant capture the'ID' value.
I tried updating the code to read:
ddlExample.DataValueField = "ID";
but it didnt work.
Any help would be appreciated.
I have a datatable dt. Within this datatable are numerous fields including 'Name' and 'ID'. Neither fields are unique.
I want to bind this datatable to my dropdownlist ddlExample, only displaying unique 'Name' values. I want the 'ID' field to be the value of the drop down list.
Can this be done?
So far, I've got the following:
var query = (from row in dt select row.Name).Distinct();
ddlExample.DataSource = query;
ddlExample.DataValueField = null;
ddlExample.DataTextField = null;
ddlExample.DataBind();
which returns unique 'Name' values, but I cant capture the'ID' value.
I tried updating the code to read:
ddlExample.DataValueField = "ID";
but it didnt work.
Any help would be appreciated.