Hi Member 13209785,
Do you just want to just display the
Id
along with
location_name
? Then a simple concatenation with the Id and displaying the concatenated item is the quickest solution for this.
SqlCommand cmd = new SqlCommand("Select top 1 * from location;", con);
The above line changes to:
SqlCommand cmd = new SqlCommand("Select top 1 *, CONVERT(VARCHAR, ID) + ' ' + location_name AS LocationNameWithId from location", con);
Then set the datasource to
LocationNameWithId
:
dropdownlist.DataTextField = "LocationNameWithId";
Also I don't see any use of the first
DataBind()
statement. You can remove that.
However, your code is vulnerable to SQL injection attacks. Please read about them and take care accordingly.