Asp.net转发器控件与checkboxlist

时间:2014-02-26 07:01:06

标签: c# asp.net

将数据绑定到转发器内的复选框列表控制ItemDataBound事件。

这是Aspx代码:

<asp:Repeater ID="rptrSelectedRcds" runat="server">
    <ItemTemplate>
        <div id="groupsDiv" runat="server">
             <div class="hidden" id="divGroupSelector" runat="server">
                  <asp:CheckBoxList runat="server" ID="chkLstGroups" 
                       RepeatDirection="Vertical">
                  </asp:CheckBoxList>
              </div>
              <asp:Button ID="btnConfirmGroups" runat="server" Text="Confirm" />
         </div>
    </ItemTemplate>
</asp:Repeater>

ItemDataBound内使用的代码将数据绑定到转发器控件:

 protected void rptrSelectedRcds_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
 {
     Int32 iProviderID = Convert.ToInt32(((Label)e.Item.FindControl("lblIndividualID")).Text);
     HtmlGenericControl selectGroupsDiv = (HtmlGenericControl)e.Item.FindControl("divGroupSelector");
        if (divGroupSelector != null)
        {
        CheckBoxList chkLstGroups = (CheckBoxList)e.Item.FindControl("chkLstGroups");
            chkLstGroups.DataSource = GetStateGroupsByProvider(stateValue, iProviderID);
            //This code line gives different values for each record
            chkLstGroups.DataTextField = "Name";
            chkLstGroups.DataValueField = "pkID";
            chkLstGroups.DataBind();
         }
    }

我可以在firebug中看到chkLstGroups的ID不同,但绑定到它的值是相同的。我希望从方法生成的每个不同的复选框ID都有不同的值 - GetStateGroupsByProvider
请帮帮我..!
谢谢!

0 个答案:

没有答案