1

我在DropDownList中继器内绑定了一个,下面是我的标记

 <asp:Repeater ID="Repeater2" runat="server" 
    onitemdatabound="Repeater2_ItemDataBound">
      <HeaderTemplate>
     <asp:DropDownList ID="DropDownList8" runat="server">
    <asp:ListItem>Select</asp:ListItem>
    <asp:ListItem>Left</asp:ListItem>
    <asp:ListItem>Right</asp:ListItem>
    <asp:ListItem>SubString</asp:ListItem>
   </asp:DropDownList>
   <asp:DropDownList ID="DropDownList7" runat="server">
 <asp:ListItem>1</asp:ListItem>
   <asp:ListItem>2</asp:ListItem>
   <asp:ListItem>3</asp:ListItem>
   </asp:DropDownList>
   <asp:DropDownList ID="DropDownList1" runat="server">
   </asp:DropDownList>
   <asp:DropDownList ID="DropDownList2" runat="server">
   </asp:DropDownList>
   <asp:Button ID="Button1" runat="server" Text="Button" />

   </HeaderTemplate>

  <FooterTemplate>
  <br />
   <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
 </FooterTemplate>
  </asp:Repeater>

 

protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
  try
  {

      if (e.Item.ItemType == ListItemType.Header)
      {

          DataTable dt = new DataTable();
          dt = Common.LoadExample();

          DropDownList ddl = (DropDownList)e.Item.FindControl("DropDownList2");
          ddl.DataSource = dt;
          ddl.DataTextField = "Name";
          ddl.DataValueField = "Name";

      }
  }
  catch (Exception ex)
  {
      throw;

  }
}

但我无法填写下拉列表,因为断点e.Item.ItemType == ListItemType.Header在这里跳过。我该如何解决这个问题?

4

1 回答 1

0

对于标题行绑定,将您的代码ItemDataBoundItemCreated

-- 更新答案 --

这仅在您添加ItemTemplate没有项目模板的情况下才有效,设置空白数据源将不会以预期的方式绑定网格。

请添加项目模板并绑定一些虚拟数据

于 2012-11-01T09:55:43.427 回答