System.Data.DataRowView in DropDownList

前端 未结 3 1323
不思量自难忘°
不思量自难忘° 2021-01-06 15:39

I am trying to populate a dropdown using values from a column. Now the problem is: I am not getting the actual values (the country codes like India(+61)) in the dropdown. In

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-06 15:52

    You are seeing what the default implementation of DataRowView.ToString() does. To pick specific fields from within the DataRow to display, do something like this.

    ddlMobile.DataSource = ds1.Tables["AllUser"];
    ddlMobile.DataTextField = "CountryCode"; // This is text displayed
    ddlMobile.DataValueField = "CountryCode"; // This is the value returned
    ddlMobile.DataBind();
    

提交回复
热议问题