forum

Home / DeveloperSection / Forums / why i am not able to use a single data table to load 2 grid controls??

why i am not able to use a single data table to load 2 grid controls??

mohan kumar 3317 05-Dec-2011
Guys!! I am stuck up here!!! why i am not able to use a single data table to load 2 grid controls??

 SqlConnection conn = new SqlConnection("Data Source=INNOVA13;uid=sa;pwd=innova;Initial Catalog=Senthil");
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            loadmyGrid1();
            loadmyGrid2();
        }
    }
    public void loadmyGrid1()
    {
        conn.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select eid,ename,gender,age,qualification,address from emp",conn);
        sda.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();
        conn.Close();
    }
    public void loadmyGrid2()
    {
        dt.Clear();
        conn.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select departmentid,deaprtmentname,studname from department", conn);
        sda.Fill(dt);
        GridView2.DataSource = dt;
        GridView2.DataBind();
        conn.Close();
    }
}

I want to use the "dt" object to load both the grid view controls simultanously with different data sources..Help me out guys...
If i use same data table object "dt" in both grid controls, i am not able to retrieve my desired output... Help me out guys!!!!

Updated on 07-Dec-2011
Having around 5 Years experience in .NET domain.

Can you answer this question?


Answer

5 Answers

Liked By