2015-09-23 38 views
0

沒有人知道如何檢查網格視圖中特定列的任何值是否與選項卡容器中的任何選項卡面板標題文本相匹配。假設網格視圖中有5列,我只想查看「產品」列中的值,我想檢查「產品」列和所有選項卡面板的值是否匹配標題文本。所有標籤面板的標題文本都是彼此不同的。如果存在匹配的值,那麼網格視圖中具有匹配值的行將被添加到與其標題文本具有相同值的標籤面板中。找到網格視圖中的特定列和標籤面板的標題文本標籤容器中的匹配值

這是我的代碼:

<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

顯然,你需要兩件事情:

  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並根據此比較做些事情。

    相關問題