在许多选项卡面板中寻找价值'选项卡容器中的HeaderText

时间:2015-09-23 04:20:56

标签: asp.net ajax tabs ajaxcontroltoolkit

有谁知道我如何搜索任何选项卡面板中是否存在文本值'标签容器中的HeaderText?

例如,我想搜索值' Selection'作为任何标签面板存在'选项卡容器中的HeaderText。我怎么能这样做?

我在网上搜索了很长一段时间,但无法找到答案。

这是我的代码:

aspx文件:

<form id="form1" runat="server">

                        

<asp:Button ID="RetrieveButton" runat="server" Height="40px" Text="Retrieve" Width="130px" OnClick="RETRIEVE_BUTTON_Click" style="font-weight:bold" BackColor="#333333" BorderColor="White" BorderStyle="Groove" ForeColor="White" ViewStateMode="Inherit" />

    <asp:GridView ID="SelectionGridView" runat="server" AllowSorting="True" AutoGenerateColumns="False" Width="100%" CellPadding="6" ForeColor="#333333" GridLines="Horizontal" BorderColor="Black" BorderStyle="Solid" BorderWidth="2px" EmptyDataText="Record Not Found" OnRowDataBound ="SelectionGridView_OnRowDataBound">
        <AlternatingRowStyle BackColor="White" />
        <columns>
            <asp:boundfield DataField="Date" HeaderText="Date"></asp:boundfield>
            <asp:boundfield DataField="Customer_ID" HeaderText="Customer ID"></asp:boundfield>
            <asp:boundfield DataField="Customer_Name" HeaderText="Customer Name"></asp:boundfield>
            <asp:boundfield DataField="Age" HeaderText="Age"></asp:boundfield>
            <asp:boundfield DataField="Product" HeaderText="Product"></asp:boundfield>         
        </columns>
        <EditRowStyle BackColor="#2461BF" />
        <FooterStyle BackColor="#507CD1" Font-Bold="False" ForeColor="Black" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="False" ForeColor="Black" BorderStyle="Solid" BorderWidth="2px" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#EFF3FB" />
        <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="False" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#F5F7FB" />
        <SortedAscendingHeaderStyle BackColor="#6D95E1" />
        <SortedDescendingCellStyle BackColor="#E9EBEF" />
        <SortedDescendingHeaderStyle BackColor="#4870BE" />
    </asp:GridView>

   <div>
         <asp:scriptmanager ID="ScriptManager1" runat="server">
        </asp:scriptmanager>
    </div>
    <asp:updatepanel ID="UpdatePanel1" runat="server">
        <contenttemplate>

    <asp:placeholder ID="PlaceHolder1" runat="server"></asp:placeholder>
        </contenttemplate>
    </asp:updatepanel></form>

cs文件:

protected void RETRIEVE_BUTTON_Click(object sender, EventArgs e)
    {
        AjaxControlToolkit.TabContainer container = new AjaxControlToolkit.TabContainer();
        container.ID = DateTime.Now.Millisecond.ToString();
        container.EnableViewState = false;
        container.Tabs.Clear();
        container.Height = Unit.Pixel(500);
        container.Width = Unit.Pixel(1200);
        container.Tabs.AddAt(0, GetManualTab());

        foreach (ListItem item in SelectionListBox.Items)
        {
            if (item.Selected)
            {
                Label tabContent = new Label();
                tabContent.ID = "lbl_tab_";
                tabContent.Text += item.Value;

                AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
                panel.HeaderText += item.Value;
                container.Tabs.Add(panel);
                panel.Controls.Add(tabContent);
            }
        }
        PlaceHolder1.Controls.Add(container);
    }

    public AjaxControlToolkit.TabPanel GetManualTab()
    {
        AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
        return panel;
    }

将根据用户从列表框中选择的值在选项卡容器中创建选项卡面板。我想根据正在创建的选项卡面板进行检查,如果指定的值存在于任何选项卡面板中。选项卡容器中的HeaderText。我已经描述了我从上面解决的问题。

感谢有人可以帮助我,非常感谢!

1 个答案:

答案 0 :(得分:1)

bool HeadersContainsText(text) { // text = "Selection"
    foreach(var control in TestTabContainer.Controls) {
        TabPanel panel = (TabPanel)control;
        if(panel.HeaderText.Contains(text)) {
            return true;
        }
    }
}