Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dynamic parent child grid

Status
Not open for further replies.
Apr 11, 2002
193
IN
Hi,

I want to create a parent child grid. Something like

Col1 Col2 Col3
+ A B C
+ D E F

When i click on + i should get..

Col1 Col2 Col3
- A 10 C --> parent row
A 5 C --> child Rows
A 3 C
A 2 C
- D 20 F
D 10 F
D 10 F

For parent row i am getting a dataset from a Web Service and for child row i am getting a dataset from another web service. Is it possible that on click of the + button i add rows to the grid dynamically as per the rows in the dataset.
I am using ASP.net 2.0 GridView. This grid should have sorting as well and the columns should be added dynamically at runtime as i don't know what are the columns. Has anyone done like this before?

Any advice would be appreciated.

Thanks,
Manish
 
If I was going to do this, I would all the rows returned. Then have the grid show in a collapsed view by default. Then, when the user clicks on the +, the child rows show. You will have to use javascript to show/hide the rows in the grid, or just use a regular table.
 
Hi,

Thanks for your response. If i have to use a table then i dont think that we can do sorting on it.
I cannot get all the records at first time. The child dataset is dependent on a couple of parent columns which i pass to get data for the child rows. It is compulsory to have 2 calls one for parent and one for child.

For dynamic template columns i have to write a class which implements ITemplate am i right or is there any other way.

Thanks,
Manish
 
Hi,

I have now created a page where in i create a TemplateColumn and BoundColumns dynamically. Here is the code

DataSet dsTemp = GetData();


if (dsTemp != null)
{
if (dsTemp.Tables.Count > 0)
{
if (gvTest.Columns.Count > 0)
{
gvTest.Columns.Clear();
}

TemplateField t = new TemplateField();

t.ItemTemplate = new CreateItemTemplateImageButton(string.Empty, "~/App_Themes/Images/plus.gif", "View", true);
gvTest.Columns.Add(t);
for (int intFor = 0; intFor < dsTemp.Tables[0].Columns.Count; intFor++)
{
//DataGrid b1 = new DataGrid();
BoundField bfield = new BoundField();
bfield.DataField = dsTemp.Tables[0].Columns[intFor].ColumnName.ToString();
bfield.HeaderText = dsTemp.Tables[0].Columns[intFor].ColumnName.ToString();
bfield.ItemStyle.Wrap = false;
bfield.HeaderStyle.Wrap = false;
gvTest.Columns.Add(bfield);
}
}
}

gvTest.DataSource = dsTemp;
gvTest.DataBind();
I get the grid with + as imagebutton template column.
I have created a class which implements ITemplate interface and has CreateItemTemplateImageButton method which creates a ItemTemplate as ImageButton. I have given ImageButton ID as "Img1" in the class.


In gvTest_RowCommand event i have written

GridView gv = (GridView)sender;
if (e.CommandName == "View")
{
ImageButton imgbtn = (ImageButton)gv.FindControl("Img1");
// replacing "Img1" with "gvTest$ctl02$Img1" which i get from the view source, doesnt work either.
imgbtn.ImageUrl = "~/App_Themes/Images/minus.gif";
}
This gives me a nullreference error. In this event itself i want to get the new dataset. Now for that i want to get data of the first two rows to send as parameters. I dont know how to do that. Now the most important thing if i want to insert new bound columns in between the clicked + and the next + then how to do that. Or is there any other way to do it.

Please advice me as this is very critical for me.

Thanks,
Manish
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top