Extending the DataGrid take 3

J

Justin Dutoit

Hey. I've posted this a couple times but I thought I'd try again.

I want to extend the Datagrid, for example, to add a title bar before the
column headers. This means leaving it to render the table tag, rendering my
row, then letting it render the remainder of the grid. I'm very concerned
that I don't mess around with the Datagrid's 'plumbing'.

For example, when you have a Template column with an asp:Label, you can
refer to it on postback using
MyGrid.Items(i).FindControl(id)
Now this is implemented by rendering a span with an id that looks like
_ctl_something. I think it is different for different browsers.

My question is, how do I avoid touching this plumbing and still extend the
Datagrid, ie what should Render() look like?
I'm looking for someone with experience in DataGrid control creation.

Thanks

Justin Dutoit
 
S

Saravana

Check out this code, it should add the title bar before the column header
and this wont affect the datagrid behaviour.

Private Sub DataGrid1_PreRender(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DataGrid1.PreRender

Dim dgItem As DataGridItem

Dim dgCell As TableCell

dgItem = New DataGridItem(1, 0, ListItemType.Header)

dgCell = New TableCell

dgCell.ColumnSpan = 3 ' (depending upon number of columns in your table
change this field..)

dgItem.Cells.Add(dgCell)

dgItem.Cells.Item(0).Text = "Title bar"

DataGrid1.Controls(0).Controls.AddAt(1, dgItem)

End Sub
 

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,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top