我有 Devexpress Tabcontrol 。 在Tabcontrol里面我有 Devexpress Grid 。 在Grid中,我通过以下代码在运行时加载按钮。
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中添加一个标签页,在第一个标签页上保留此网格。
但是它没有被添加,它在按钮上点击了
我刚为标签页创建了一个对象,并加载了 Gridcontrol.ascx 用户控件,该控件具有devexpress gridview。 之后,我在 Tabpage usercontrol 中调用 addTabPages 方法,并将此 Tabpage 对象作为参数传递给它。在下面的代码中 tabPreview 是 Tabcontrol usercontrol 的对象。
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 :(得分:1)
在您的aspx页面中:
这是代码:
<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;
}
这可能会对你有帮助。