Format DropDownList.TextValue

后端 未结 7 1578
失恋的感觉
失恋的感觉 2020-12-15 10:54

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 :



        
7条回答
  •  别那么骄傲
    2020-12-15 12:00

    You can achieve it by following code

    dsStudent.Tables[0].Columns.Add("IdWithStudenName",typeof(string),"Id + ' - ' + StudenName");
    DropDownList1.DataSource = dsStudent;
    DropDownList1.DataTextField = "IdWithStudenName";
    DropDownList1.DataBind();
    DropDownList1.Items.Insert(0, new ListItem("Please select"));
    

    For more understanding refer here.

提交回复
热议问题