<asp:datalist id="Datalist1" runat="server" DataKeyField="id" ExtractTemplateRows="True" HorizontalAlign="Center" Width="100%" GridLines="Both" BorderWidth="1px">
   <HeaderTemplate>
      <Asp:Table Runat="Server" Width="760" ID="Table3">
          <Asp:TableRow Runat="Server" HorizontalAlign="Center" ID="Tablerow3">
              <Asp:TableCell Runat="Server" ID="Tablecell13">序</Asp:TableCell>
              <Asp:TableCell Runat="Server" ID="Tablecell17">责任部门</Asp:TableCell>
              <Asp:TableCell Runat="Server" ID="Tablecell18">车间</Asp:TableCell>
</Asp:TableRow>
       </Asp:Table>
   </HeaderTemplate>
  <ItemTemplate>
      <Asp:Table Runat="Server" ID="Table4">
<Asp:TableRow Runat="Server" HorizontalAlign="Center" ID="Tablerow4">
             <Asp:TableCell Runat="Server" ID="Tablecell22">
           <Asp:Label Runat="server" ID="txtNos"></Asp:Label>
    </Asp:TableCell>
           <Asp:TableCell Runat="Server" ID="Tablecell25">
                  <asp:DropDownList id="DropDownList1" runat="server">
</asp:DropDownList>
  </Asp:TableCell>
   <Asp:TableCell Runat="Server" ID="Tablecell26">
     <asp:DropDownList id="Dropdownlist2" runat="server"></asp:DropDownList>
</Asp:TableCell>
    </Asp:TableRow>
  </Asp:Table>
</asp:datalist>
如代码中的DropDownlist怎样和一个数据库表的字段绑定?

解决方案 »

  1.   

    在itemDatabound中,先查询数据库表的某个字段,然后根据返回的结果绑定dropdownlist
      

  2.   

    在itemDatabound事件中
    找到这个dropdownlist然后就可以绑定了
      

  3.   

    参考一下:
    <asp:DropDownList DataTextField="mc" DataValueField="lsh"
                  DataSource='<%# GetSource() %>' id=ddl_yplx runat="server" Width="100%" 
    SelectedValue='<%# DataBinder.Eval(Container, "DataItem.type") %>'>
    </asp:DropDownList>
    后台:
    protected DataSet GetSource()
    {
        return [数据集];
    }
      

  4.   

    同意樓上,另:
    --------------------------------------------------------
    SelectedValue='<%# DataBinder.Eval(Container, "DataItem.type") %>'
    也可以:
    SelectedValue='<%# Container.DataItem("YourField") %>'
    --------------------------------------------------------
      

  5.   

    数据库一般都有存储表字段的数据表,如SQL Server,可以通过查询该表获得字段列表。不过你所用的数据库用户要有足够的权限。
      

  6.   

    像DataGrid一样。
    this.DDL.DataSource=ds;
    this.DDL.DataBind();
    this.DDL.DataTextField="字段";
    this.DDL.DataValueField="字段";