0

我的 asp 内容页面中有一个未绑定的下拉列表,后面有以下代码

 using (SqlConnection myConnection = new SqlConnection  
      (ConfigurationManager.ConnectionStrings["conn"].ToString()))
         {

            try
            {


      SqlDataAdapter myDAMgr = new SqlDataAdapter("SELECT  UserId from  
      dbo.LoanOwnerStampManager ", myConnection);

                myDAMgr.Fill(Manager);

                ddlManagerName.DataTextField = "UserId";
                ddlManagerName.DataValueField = "UserId";
                ddlManagerName.DataBind();
            }  // end try


            catch (Exception ex)
            {
                ex = ex.InnerException;


            }

            finally
            {
                myConnection.Dispose();
            }
         ddlManagerName.Items.Insert(0, new ListItem("Select", "0"));  // this  is   the Initial Value for the dropdownlist.
        } // end Using

现在在我的 ASP 页面中,没有什么特别的

 <asp:Label ID="lblManager" Text ="Manager's Name" runat="server" Font-Bold="True" 
  style="margin-right: 10px"
    ForeColor="#003366" ></asp:Label>
 <asp:DropDownList ID="ddlManagerName"  runat="server" Height="22px" 
    style="margin-left: 6px" Width="128px"></asp:DropDownList>

但是下拉列表永远不会被填充!希望另一双眼睛能找出错误。

4

2 回答 2

1

你从来没有DataSource为下拉设置。

我假设您要绑定到Manager(您填写的 DataSet),如下所示:

ddlManagerName.DataSource = Manager;
于 2013-07-25T18:10:11.333 回答
0

你忘了打开连接。

 using (SqlConnection myConnection = new SqlConnection  
      (ConfigurationManager.ConnectionStrings["conn"].ToString()))
         {

            try
            {
              myConnection.Open();
              Your code as it was

ddlManager.DataSource = Manager;

ddlManager.DataValueField= "ValueColumnOfDataTable";
ddlManager.DataTextFiedl="TextColumn";
ddlManager.DataBind();
ddlManager.Items.Insert(0, new ListItem("---Select---","-1"));
于 2013-07-25T18:11:43.283 回答