My stored procedure is like this
SELECT Id, StudentName
FROM xyz
I have a drop down list in asp.net, which I am loading as :
ddlA.DataSource = // Some source
ddlA.DataTextField = "Id" + " -" + "StudentName";
ddlA.DataValueField = "Id";
ddlA.DataBind();
ddlA.Items.Insert(0, new ListItem(" Select one", "0"));
But at the Databind() statement, I am getting this error:
System.Web.HttpException: DataBinding: ‘System.Data.DataRowView’ does not contain a property with the name ‘Id-StudentName’.
In text part of the dropdown list, I want to display the concatenated value of Id - StudentName.
How can I do it?
It seems that it’s not achievable automatically, e.g. see this MS Connect ticket.
Thus do that programmatically:
or