-3

我目前很难从数据库列中检索值并将该值分配给 dropdownlist.selecteditem.text。我有类似的查询

SELECT [ProductName]+' '+ '('+[Category]+')' As  ProductNameCategory From Products

我想将查询结果分配给下拉列表。像这样

dropdownlist.selecteditem.text=ProductNameCategory
4

1 回答 1

0

你可以在 DDL 上调用 DisplayMember 吗?

以下是 Windows 应用程序的语法。像ddl一样设置组合框的地方。您需要告知要绑定的值。

        try //Try block for opening, querying and displaying pulled data
        {
            SqlConnection sqlConn = new SqlConnection("ConnString"); //Connection String
            sqlConn.Open();
            using (SqlDataAdapter dataadapter = new SqlDataAdapter("Select * from Test_Names", sqlConn))
            {
                var table = new DataTable();
                a.Fill(table);           
                comboBox1.DataSource = t;       
                comboBox1.DisplayMember = "FirstName"; //name of Column/DisplayName
                comboBox1.ValueMember = "Firstname"; //Name of Column/Value          
             }                                    
         }
        sqlConn.Close(); //Close Conn
        catch (Exception ex)
        {
        //handle errors
        } //End Try Catch for SQL Operations
于 2013-08-19T18:15:51.397 回答