Datagrid Detail Row

U

ujjc001

Hello all-
I am looking for a way to add a detail row to a datagrid.
In theory I would think I would have to somehow, when the selected
index changes, add a div layer, or perhaps make a pre existing div
layer visible (style display = inline, not display = none). Perhaps
the div could be added somehow in the itemcreated event or something.
I have found this --
http://www.denisbauer.com/ASPNETControls/HierarGridDemo.aspx -- but I
would like something simpler where I can add a button, label, etc to
this row and control it myself. Denis made a great solution but I want
to handle it myself. Also, I couldn't follow his source code so that
didn't help :eek:)

Also, I've seen creating another column and hacking the html output
creating code to close the td's and adding a tr with a colspan = to all
your rows. That could work if I can selectivly have that column show
based on a boolean value - open/closed, perhaps a button that you check
the name of, ie. if btn = btnopen then run open code, else if btn =
btnclose then close the row... Somehow though, I would like to be able
to track which ones are open though so on post back they will show
again... Forgive my thinking out loud but just trying to spark some
ideas.


Why isn't there anything else on the net for this? I haven't been able
to find anything.

Thanks for any help on this one.
 
J

John Saunders

Hello all-
I am looking for a way to add a detail row to a datagrid.
In theory I would think I would have to somehow, when the selected
index changes, add a div layer, or perhaps make a pre existing div
layer visible (style display = inline, not display = none). Perhaps
the div could be added somehow in the itemcreated event or something. ....
Why isn't there anything else on the net for this? I haven't been able
to find anything.

It is there. It's called a template column. You can put whatever you like in
a template column.

Unfortunately, it's not quite that easy. You'll be starting off with one row
of a table with "n" columns. You'll want to change that to one row with one
column with a colspan of "n". Inside that column, you may want to add a
table whose first row has the original "n" columns. The second row of this
table can have whatever you want for details.

This is as opposed to adding an extra row which the DataGrid doesn't know
anything about. I've seen it handle having cells removed, but I don't know
about adding rows.

John Saunders
 
U

ujjc001

I know template columns and datagrids, perhaps we've cross our
thoughts.
Are you suggesting that I make a datagrid with one column and in that
add another datagrid? I guess you are loosing me on that one.

Or are you suggesting I somehow edit the colspan on my last column?

Here's my situation,
I need a datagrid with 5 columns and under that, once selected, I'd
like to display a single row with a colspan of 5 when you click on a
button in column 5.
|1 |2 |3 |4 |5
| 1 |


Here is my html- How can I get the column "longstringhere" to be in a
new row, only visible when I say so, persist across postbacks, and have
a colspan of 5.

.....
<asp:TemplateColumn HeaderText="Name">
<EditItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.name") %>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="LongStringHere">
<EditItemTemplate>
<%# DataBinder.Eval(Container, "DataItem.ls") %>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>

Again, please see the example at
http://www.denisbauer.com/ASPNETControls/HierarGridDemo.aspx

I really appreciate your help but I don't think were understanding each
other :eek:)
Jeff
 
J

John Saunders

ujjc001 said:
I know template columns and datagrids, perhaps we've cross our
thoughts.
Are you suggesting that I make a datagrid with one column and in that
add another datagrid? I guess you are loosing me on that one.

Or are you suggesting I somehow edit the colspan on my last column?


I'm suggesting that in the click event for your column 5 button that you
edit the row containing that button. My suggestion was that you replace:

<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>

With:

<tr>
<td colspan="5">
<table width="100%">
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<!-- Your details here -->
</tr>
</table>
</td>
</tr>

Recall that a DataGridItem is a TableRow, which contains TableCell objects.

John Saunders
 
U

ujjc001

Ok, I follow now. How would you code that? Can you provide an
example? Also, wouldn't the viewsate keep these rows until you leave
the page or click the button?
 
J

John Saunders

ujjc001 said:
Ok, I follow now. How would you code that? Can you provide an
example? Also, wouldn't the viewsate keep these rows until you leave
the page or click the button?

Sorry, I don't have an example around. On a previous job, I did this sort of
thing to turn the footer line into a summary row.

Also, keep in mind that you would only execute this code upon a button
click. The viewstate of the former cells would get erased when the cells get
removed.

John Saunders
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top