查找网格视图中特定列与选项卡容器中选项卡面板标题文本之间的匹配值



有人知道我如何检查从网格视图中的特定列的任何值是否与标签容器中的任何标签面板的标题文本匹配。假设在网格视图中有5列,我只想查看"Product"列的值,我想检查"Product"列的值和所有选项卡面板的标题文本之间是否存在匹配值。所有选项卡面板的标题文本彼此不同。如果存在匹配值,则网格视图中具有匹配值的行将被添加到具有与其标题文本相同值的选项卡面板中。

这是我的代码:

<asp:ListBox ID="SelectionListBox" runat="server" AppendDataBoundItems="True" SelectionMode="Multiple" Height="130px" Width="350px">
<asp:ListItem Text="Apple" Value ="1"  />
<asp:ListItem Text="Watermelon" Value ="2"  />
<asp:ListItem Text="Kiwi" Value ="3"  />
<asp:ListItem Text="Plum" Value ="4"  />
<asp:ListItem Text="Pineapple" Value ="5"  />

<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>

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;
    }
如果有人能在这方面给我提供帮助,非常感谢!

显然你需要两件事:

  1. 获取标签头文本:
foreach(Control control in Tabs.TabContainer1) {
            TabPanel tab = (TabPanel)control;
            string headerText = tab.HeaderText;
        }
  • 获取GridView列内的行文本:
  • for (int currentRow = 0; currentRow < GridView1.Rows.Count; currentRow++)
    {
        string cellText = GridView1.Rows[currentRow].Cells[targetColumn].Text;
    }
    

    然后您只需将headerTextcellText进行匹配,并根据此比较执行操作。

    相关内容

    • 没有找到相关文章

    最新更新