Nesting Datagrids

  • Thread starter Thread starter Edward
  • Start date Start date
E

Edward

Try Binding your second datagrid in the ItemDatabound
event of your first datagrid. Your second datagrid becomes
a child control of the cell where your second datagrid is.
Make a reference to that child control (which is the
nested datagrid) and do the normal binding procedures.

Hope this helps.
 
Thanks for replying,
I just tried this and it says that my second
datagrid "dg2" is not declared?
 
The referencing of the datagrid control is probably wrong.
Suppose your nested datagrid is in the second column of
your parent datagrid. Here's a code snippet which is not
well written on my part. :)
Using the itemdatabound event of the parent datagrid, you
have:

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType
== ListItemType.AlternatingItem)
{
TableCell iCell = (TableCell)e.Item.Cells[1];
DataGrid dg = (DataGrid)iCell.Controls[1];
SqlConnection sqlCon = new SqlConnection("some con
string");
sqlCon.Open();
SqlCommand sqlCom = new SqlCommand("some sql string here",
sqlCon);
sqlCom.CommandType = CommandType.Text;
SqlDataReader dr = sqlCom.ExecuteReader();
dg.DataSource = dr;
dg.DataBind();
sqlCon.Close();
}

Hope this helps
 
Thnaks a lot for your help, I have this working now

-----Original Message-----
The referencing of the datagrid control is probably wrong.
Suppose your nested datagrid is in the second column of
your parent datagrid. Here's a code snippet which is not
well written on my part. :)
Using the itemdatabound event of the parent datagrid, you
have:

if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType
== ListItemType.AlternatingItem)
{
TableCell iCell = (TableCell)e.Item.Cells[1];
DataGrid dg = (DataGrid)iCell.Controls[1];
SqlConnection sqlCon = new SqlConnection("some con
string");
sqlCon.Open();
SqlCommand sqlCom = new SqlCommand("some sql string here",
sqlCon);
sqlCom.CommandType = CommandType.Text;
SqlDataReader dr = sqlCom.ExecuteReader();
dg.DataSource = dr;
dg.DataBind();
sqlCon.Close();
}

Hope this helps
-----Original Message-----
Thanks for replying,
I just tried this and it says that my second
datagrid "dg2" is not declared?

.
.
 
Back
Top