2012-01-11 84 views
0

我有一個Devexpress Tabcontrol。 在Tabcontrol裏面我有Devexpress Grid。 在那個網格里面我按照代碼在運行時加載按鈕如何在Devexpress TabControl上添加按鈕點擊的標籤頁?

GridViewCommandColumn col = new GridViewCommandColumn(); 
GridViewCommandColumnCustomButton CusButton = new GridViewCommandColumnCustomButton(); 
CusButton.ID = "btn1"; 
CusButton.Image.Url = "~/Images/color.jpg";  
col.ButtonType = ButtonType.Image; 
col.CustomButtons.Add(CusButton); 
gridview.Columns.Add(col); 

現在對按鈕點擊,我需要在DevExpress的自定義的Tabcontrol添加一個標籤頁保留第一個選項卡上這個網格。

但它沒有得到補充,它得到刷新該按鈕點擊

我剛剛創建的對象爲標籤頁,加載具有的DevExpress GridView的Gridcontrol.ascx用戶控制。 之後我就叫addTabPages方法在我TabPage的用戶控件和it.In通過這個標籤頁對象作爲參數下面的代碼tabPreview自定義的Tabcontrol用戶控件的對象。

tabpagenew = new TabPage(); 
Gc = (GridControl)Page.LoadControl(@"GridControl.ascx"); 
Gc.ID = "GC" + currDDIndex; 
ASPxGridView grdPreview = (ASPxGridView)Gc.FindControl("ggc_preview"); 
grdPreview.ID = "grd" + currDDIndex; 
tabpagenew.Controls.Add(Gc); 
tabPreview.addTabPages(tabpagenew); 

addTabPages方法,我只是說由它的索引Tab頁,

public void addTabPages(TabPage tab_Page) 
{ 
    ActiveIndex = ASPxPageControl1.ActiveTabIndex + 1; 
    int index = ASPxPageControl1.TabPages.Count + 1; 
    ASPxPageControl1.TabPages.Add(tab_Page); 
    tab_Page.ToolTip = tab_Page.Text; 
    tab_Page.Name = tab_Page.Name;     
    ImageButton button = new ImageButton(); 
    button.ImageUrl = "~\\Images\\close.png"; 
    button.Style.Add(HtmlTextWriterStyle.Cursor, "Hand"); 
    button.Click += new ImageClickEventHandler(Close_Click); 
    button.Attributes.Add("onclick", "TabClose('" + hdnCurrentTab.ClientID + "','" + tab_Page.Index + "');");    
    tab_Page.TabTemplate = new AddTabHeading(button, tab_Page.Text, ASPxPopupMenu1, ASPxPageControl1.ActiveTabPage.VisibleIndex, ASPxPageControl1);     
} 
+0

你可以發佈完整的代碼或至少是添加標籤頁的部分嗎? – Filip 2012-01-11 07:56:13

+0

@Filip:我只是通過添加Tab頁面代碼簡單地編輯了描述。 – 2012-01-18 07:48:40

+0

按鈕點擊後是否執行addTabPages? – Filip 2012-01-18 10:24:13

回答

1

在你的aspx頁面:

  1. 你需要把ASP的選項卡控件:UpdatePanel中。
  2. 在隱藏的DIV中添加一個按鈕。
  3. 無論何時需要添加新選項卡,請調用按鈕點擊功能。

這是代碼:

<asp:UpdatePanel runat="server" ID="ClientDetailsUpdatePanel" > 
    <ContentTemplate> 
     <div style="display:none"> 
      <asp:Button ID="CallBackHiddenButton" runat="server" OnClick="CallBackHiddenButton_Click" Text="Button"/> 
     </div> 

     <dx:ASPxPageControl ID="DetailsClientTabs" ClientInstanceName="DetailsClientTabs" runat="server" ActiveTabIndex="0" 
      ActiveTabStyle-Border-BorderStyle="None" EnableCallBacks="false" 
      ActiveTabStyle-BackColor="Transparent" ContentStyle-BackColor="Transparent" 
      ContentStyle-BorderRight-BorderStyle="None" ContentStyle-BorderLeft-BorderStyle="None" 
      ContentStyle-BorderTop-BorderStyle="None" ContentStyle-BorderBottom-BorderStyle="None" 
      EnableTheming="False" ContentStyle-Border-BorderColor="Transparent"> 

     </dx:ASPxPageControl> 
    </ContentTemplate> 
</asp:UpdatePanel> 

現在,在你的C#代碼:

1-處理按鈕點擊添加了新的一頁:

protected void CallBackHiddenButton_Click(object sender, EventArgs e) 
    { 
     TabPage newPage = new TabPage("test" + DateTime.Now.Second, "maged" + DateTime.Now.Second); 
     DetailsClientTabs.TabPages.Add(newPage); 

     //You always need to reassign the previous tabs pages 
     for (int i = 0; i < DetailsClientTabs.TabPages.Count; i++) 
     { 
      Control cc = Page.LoadControl("~/Forms/Client/Details/TabsPages/TestUserCtrl.ascx"); 
      cc.ID = String.Format("control_di_", DateTime.Now); 
      DetailsClientTabs.TabPages[i].Controls.Add(cc); 
     } 

     //If you need to get the new added tab to be the active one! 
    DetailsClientTabs.ActiveTabIndex = DetailsClientTabs.TabPages.Count - 1; 
     } 

這可能有助於您。