AJax Tab容器的动态ActiveTabChanged

时间:2012-12-21 08:28:29

标签: asp.net ajax dynamic-data

如何为ActiveTabChanged解雇TabContainer。我编写了一个代码来填充数据库中的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,但事件发生时标签容器不可见。

这是我的示例输出

enter image description here

在点击计算机时,我想加载带有这些细节的网格,以便有人帮助我

1 个答案:

答案 0 :(得分:0)

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

  

OnActiveTabChanged = “TabContainer1_ActiveTabChanged”   的AutoPostBack = “真”