Nesting Datagrids

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.
 
G

Guest

Thanks for replying,
I just tried this and it says that my second
datagrid "dg2" is not declared?
 
E

Edward

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
 
G

Guest

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?

.
.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top