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
Forums Home / ComponentOne / ASP.NET Web Forms Edition
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
Posted 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
Posted 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