2014-03-24 60 views
0

是否可以使用單個gridview並將其顯示在多個選項卡上(ajax tabcontainer)? 我想要將不同的數據源綁定到不同選項卡上的網格。目前我正在使用3個gridviews(3個標籤)。多個選項卡上的單個gridview

<asp:TabContainer ID="TabContainer1" runat="server" UseVerticalStripPlacement="True" AutoPostBack="true" OnActiveTabChanged="TabContainer1_ActiveTabChanged"> 
     <asp:TabPanel ID="tp1" runat="server"> 
      <HeaderTemplate> 
       Tab 1 
      </HeaderTemplate> 
      <ContentTemplate> 
       <p>test tab 1</p> 
       <asp:GridView ID="GridView1" runat="server" Width="100%" 
        ViewStateMode="Enabled" OnRowEditing="GridView1_RowEditing"> 
        <Columns> 
         <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> 
        </Columns> 
       </asp:GridView> 
      </ContentTemplate> 
     </asp:TabPanel> 
     <asp:TabPanel ID="tp2" runat="server"> 
      <HeaderTemplate> 
       Tab 2 
      </HeaderTemplate> 
      <ContentTemplate> 
       <p>test tab 2</p> 
       <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="True" Width="100%" 
        ViewStateMode="Enabled"> 
       </asp:GridView> 
      </ContentTemplate> 
     </asp:TabPanel> 
     <asp:TabPanel ID="tp3" runat="server"> 
      <HeaderTemplate> 
       Tab 3 
      </HeaderTemplate> 
      <ContentTemplate> 
       <p>test tab 3</p> 
       <asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="True" Width="100%" 
        ViewStateMode="Enabled"> 
       </asp:GridView> 
      </ContentTemplate> 
     </asp:TabPanel> 
    </asp:TabContainer> 

代碼後面:

protected void TabContainer1_ActiveTabChanged(object sender, EventArgs e) 
{ 

    try 
    { 
     if (TabContainer1.ActiveTabIndex == 0) 
     { 

      //bind datasource 1; 

     } 
     if (TabContainer1.ActiveTabIndex == 0) 
     { 

      //bind datasource 2; 

     } 
    }etc. 

回答

0

用於示出2

tp2.Controls.Add(GridView1); 

一般形式

<TabPanelID>.Controls.Add(<GridviewID>); 
在一個tabpanel gridview1