1

如何开火ActiveTabChangedTabContainer我已经编写了一个代码来TabPanel从数据库中填充 HeaderText,这是我的代码

public partial class dynamicTab : System.Web.UI.Page
{
    string strCon = ConfigurationManager.ConnectionStrings["SqlCon"].ConnectionString.ToString();
    TabContainer ajxTab;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           // createTab();
            pnlDynamic.Controls.Add(ajxTab);
            ajxTab_ActiveTabChanged(ajxTab, EventArgs.Empty);
        }
    }

    private void ajxTab_ActiveTabChanged(TabContainer ajxTab, EventArgs eventArgs)
    {
        SqlConnection con = new SqlConnection(strCon);
        SqlCommand cmd = new SqlCommand("select * from Employee where DeptID='" + ajxTab.ActiveTab.ID.ToString() + "'", con);
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);

        GridView grd = new GridView();
        grd.AutoGenerateColumns = true;
        grd.DataSource = ds;
        grd.DataBind();
        pnlDynamic.Controls.Add(grd);
    }

    protected void page_init(object sender, eventargs e)
    {
        createtab();

    }

    private void createTab()
    {
        SqlConnection con = new SqlConnection(strCon);
        SqlCommand cmd = new SqlCommand("select DeptID,DepartmentName from Department", con);
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataSet ds = new DataSet();
        da.Fill(ds);
        ajxTab = new AjaxControlToolkit.TabContainer();
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            TabPanel pnl = new TabPanel();
            pnl.HeaderText = ds.Tables[0].Rows[i]["DepartmentName"].ToString();
            pnl.ID = ds.Tables[0].Rows[i]["DeptID"].ToString();
            ajxTab.Tabs.Add(pnl);
            ajxTab.ActiveTabIndex = 0;
        }
    }
}

第一次ActiveTabChanged完美触发,但是当我单击第二个选项卡时ActiveTabChanged没有被触发。我尝试通过设置ajxTab.AutoPostBack=true但事件发生时选项卡容器不可见。

这是我的示例输出

在此处输入图像描述

在单击计算机时,我想加载带有这些详细信息的网格,所以有人可以帮助我

4

1 回答 1

0

您可以在 OnActiveTabChanged 事件中绑定每个选项卡的内容

OnActiveTabChanged="TabContainer1_ActiveTabChanged" AutoPostBack="true"

于 2012-12-21T08:36:50.500 回答