1

大家好,我试图在我的下拉列表中显示数据库值,我已经为它创建了存储过程,并试图通过在我的代码中调用该存储过程来获取值,但我无法显示它。请帮帮我

   protected void DrpClientName_SelectedIndexChanged(object sender, EventArgs e)   
   {

        MTMSDTO objc = new MTMSDTO();
        {
            objc.ClientName = Convert.ToString(Session["ClientName"]);
            DataSet ClientN = obj.GetClientList();
            DataView Projview = new DataView();
            Projview.Table = ClientN.Tables[0];
            DrpClientName.DataSource = Projview;
            DrpClientName.DataBind();
        }
    } 
4

2 回答 2

1

你没有写你想要显示的内容......你必须使用DisplayMember ValueMember.

尝试这个:

objc.ClientName = Convert.ToString(Session["ClientName"]);
DataSet ClientN = obj.GetClientList();
DataView Projview = new DataView();
Projview.Table = ClientN.Tables[0];
DrpClientName.DataSource = Projview;
DrpClientName.DisplayMember = "Column name that you want to display";
DrpClientName.ValueMember = "Column name that you want to get the values from";

祝你好运。

于 2013-06-19T07:00:54.873 回答
1

不要在下拉列表中编写代码选择索引更改事件将其写入函数并在页面加载事件中调用它

你必须设置 DataTextField 和 DatavalueField

objc.ClientName = Convert.ToString(Session["ClientName"]);
            DataSet ClientN = obj.GetClientList();
            DataView Projview = new DataView();
            Projview.Table = ClientN.Tables[0];
            DrpClientName.DataSource = Projview;
            DrpClientName.DataTextField="Description";
            DrpClientName.DataValueField="ID";
            DrpClientName.DataBind();
于 2013-06-19T06:54:27.737 回答