c1webgrid doesn't have RowDataBound event

Posted by: kbeyene on 17 January 2018, 1:27 am EST

  • Posted 17 January 2018, 1:27 am EST

    Hello,
    I am trying to do nested grid using c1webgrid. User be able to see child grid on click of master grid how ever c1webgrid doesn't have
  • Marked as Answer

    Replied 17 January 2018, 6:03 pm EST

    Hi,
    Please refer to the following demo sample to add Grid inside grid:
    http://demo.componentone.com/aspnet/ControlExplorer/C1GridView/HierarchicalGrid.aspx

    Let us know if you have any further queries.

    ~Manish
  • Replied 18 December 2018, 7:43 pm EST

    You may try this code.

    Binding the Customers records to the Parent GridView
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    gvCustomers.DataSource = GetData("select top 10 * from Customers");
    gvCustomers.DataBind();
    }
    }

    private static DataTable GetData(string query)
    {
    string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
    using (SqlConnection con = new SqlConnection(strConnString))
    {
    using (SqlCommand cmd = new SqlCommand())
    {
    cmd.CommandText = query;
    using (SqlDataAdapter sda = new SqlDataAdapter())
    {
    cmd.Connection = con;
    sda.SelectCommand = cmd;
    using (DataSet ds = new DataSet())
    {
    DataTable dt = new DataTable();
    sda.Fill(dt);
    return dt;
    }
    }
    }
    }
    }

    Binding the Child GridView with the Orders for each Customer in the Parent GridView
    protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    string customerId = gvCustomers.DataKeys[e.Row.RowIndex].Value.ToString();
    GridView gvOrders = e.Row.FindControl("gvOrders") as GridView;
    gvOrders.DataSource = GetData(string.Format("select top 3 * from Orders where CustomerId='{0}'", customerId));
    gvOrders.DataBind();
    }
    }

    Client side Expand Collapse functionality using jQuery and JavaScript
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript">
    $("[src*=plus]").live("click", function () {
    $(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
    $(this).attr("src", "images/minus.png");
    });
    $("[src*=minus]").live("click", function () {
    $(this).attr("src", "images/plus.png");
    $(this).closest("tr").next().remove();
    });
    </script>
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels