You must Sign In to post a response.
  • Category: Windows

    Trreview inside datagridview dynamically

    I have to create treeview inside Datagridview.



    + Mar 01

    + Mar 02

    + Mar 03


    I have data inside datatable with 5 columns including date column(Mar 01/02/03)

    When I click of "+" sign of Mar 01, it should display records of Mar 01 alone from datatable.
    When I click of "+" sign of Mar 02, it should display records of Mar 02 alone from datatable.
    When I click of "+" sign of Mar 03, it should display records of Mar 03 alone from datatable.

    how is it possible?
  • #765275
    Hi lilly,

    This is called as nested gridview concept, that means you have to bind child grid for each record of parent grid, when you click on "+" symbol you have to expand the child grid records irrespective of parent record.

    Bind child grid records onrowdatabound event of parent grid. and call the parent grid on page load event.

    Ex:

    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    Bind_Student();
    }
    }

    protected void Bind_Student()
    {
    cmd = new SqlCommand("Get_Student_Mark_Details", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@Trans_Type", "student");
    cmd.Parameters.AddWithValue("@STUDENT_ID", Student_Id);
    cmd.Parameters.AddWithValue("@CLASS_ID", Class_Id);
    dt = new DataTable();
    try
    {
    con.Open();
    da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
    gvStudent.DataSource = dt;
    gvStudent.DataBind();
    }
    }
    catch (Exception ex)
    {
    }
    finally
    {
    con.Close();
    con.Dispose();
    }
    }
    protected void gvStudent_OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    string StuentId = gvStudent.DataKeys[e.Row.RowIndex].Value.ToString();
    GridView gvClass = e.Row.FindControl("gvClass") as GridView;
    cmd = new SqlCommand("Get_Student_Mark_Details", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@Trans_Type", "class");
    cmd.Parameters.AddWithValue("@STUDENT_ID", StuentId);
    cmd.Parameters.AddWithValue("@CLASS_ID", Class_Id);
    dt = new DataTable();
    try
    {
    da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
    gvClass.DataSource = dt;
    gvClass.DataBind();
    }
    }
    catch (Exception ex)
    {
    }

    }
    }


    If you want to know in depth of this then refer below link, in this article I will explore the same.

    http://www.dotnetspider.com/resources/45078-Nested-GridView-with-Extendable.aspx

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765300
    @naveen.

    I havenot create a treeview too inside grid.. (with plus sign). How to make it

  • #765301
    Hi lily,

    Why treeview is required in your case, as per my understand your post you need to hide the child records at initial loading, once you click on "+" symbol you want to explore the records, that is you want right?

    If that is your requirement then refer above link which I gave you in my above response.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #765307
    Hi
    Ofcourse

    Master data bind in your grid then when you click master data navigate the another grid show the transaction data
    like this.

    you can go through link

    "social.msdn.microsoft.com/Forums/windows/en-US/a44622c0-74e1-463b-97b9-27b87513747e/windows-forms-data-controls-and-databinding-faq?forum=winformsdatacontrols#faq8"

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.


Sign In to post your comments