System.Data.DataRowView中的DropDownList [英] System.Data.DataRowView in DropDownList

查看:205
本文介绍了System.Data.DataRowView中的DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用填充从列值的下拉列表。现在的问题是:我不是在下拉列表中获取实际值(国codeS像印度(+61))。相反,我得到System.Data.DataRowView(多次)在下拉列表中。

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. Instead I am getting "System.Data.DataRowView" (multiple times) in the dropdown.

 public void bind()
 {
    DataSet ds1 = new DataSet();
    SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"]);
    con.Open();
    string strQuery = "select CountryCode from AUser";
    SqlCommand cmd = new SqlCommand(strQuery, con);
    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
        da.Fill(ds1, "AUser");
    ddlMobile.DataSource = ds1.Tables["AUser"];
    ddlMobile.DataBind();
    con.Close();
}

我呼吁的Page_Load bind方法。为国家code 数据类型为 VARCHAR(50)&安培;值是像印度(+91)澳大利亚(+61)等...

I am calling the bind method on page_load. Data type for CountryCode is varchar(50) & values are like India(+91), Australia(+61) etc...

推荐答案

您应该设置 DataValueField DataTextField 下拉的属性。

You should set the DataValueField and DataTextField Properties of the drop down.

ddlMobile.DataSource = ds1.Tables["AUser"];
ddlMobile.DataValueField = "CountryCode";
ddlMobile.DataTextField = "CountryName";
ddlMobile.DataBind();

下面国家code和国家或地区名称必须对应于您的DataRow这些值的列名

Here CountryCode and CountryName must be the column names corresponding to those values in your DataRow

这篇关于System.Data.DataRowView中的DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆