如何在 AJAX 选项卡容器内获取 ASP.NET 复选框列表对象

3

我在 AJAX 标签容器内插入了一个 ASP.NET 复选框列表控件。现在我需要创建该控件的对象,以便在我的 C# 代码后台文件中访问复选框列表。

以下是我创建复选框列表的 HTML 代码:

<ajaxToolkit:TabContainer ID="tcPrescription" runat="server" Height="444px">
    <ajaxToolkit:TabPanel runat="server" ID="indoor" Height="430px">
        <HeaderTemplate>
          Indoor Prescription
        </HeaderTemplate>
        <ContentTemplate>
            <div id="bottomcontainer" style="height:420px;">
                <div id="bottomleft" style="float:left;height:420px;width:400px;text-align:center;">
                    <asp:Panel ID="pnlMedicines" runat="server" HorizontalAlign="Center" 
                        ScrollBars="Vertical" Height="375px" Width="389px">
                    <center>
                        <asp:CheckBoxList ID="cblMedicines" runat="server" BackColor="White" 
                            BorderColor="#669900" BorderStyle="Solid" BorderWidth="1px" 
                            Height="350px" Font-Bold="False" ForeColor="Black" Width="316px"
                            DataSourceID="dsMedicines" DataTextField="MedicineName"
                            DataValueField="MedicineName" >
                        </asp:CheckBoxList>
            ...
        </ContentTemplate>
    </ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

以下是我的后端文件中的代码:

CheckBoxList cblMedicines = (CheckBoxList)tcPrescription.FindControl("cblMedicines");

它返回cblMedicinesnull对象。那么我如何访问AJAX选项卡容器内部的复选框列表控件呢?
请帮助我解决这个问题。

1
pnlMedicines.FindControl("cblMedicines") 怎么样? - Shai
是的,就是这样。非常感谢你,Shai... 你救了我的一天 :) - Jake
1
@lpjanaka,我已经发布了一个答案,请接受它以造福大众。祝你好运! - Shai
1个回答

2
您可以尝试使用。
CheckBoxList cblMedicines = (CheckBoxList)pnlMedicines.FindControl("cblMedicines");

相反。

cblMedicines 位于 pnlMedicines 控件中;在后者的子元素中查找它更为常见。

祝你好运!


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接