controls.add overwrites cell text - boo!

D

DaveyP

I have a user control (called data_dictionary) which I need to add
into the header text of a datagrid. I'm doing this by adding the
control in the RowCreated event as follows:

dds_descriptions is an arraylist of strings. data_dictionary is the
user control

Code:
    Sub gvw_data_RowCreated(ByVal sender As Object, ByVal e As
GridViewRowEventArgs)

        Dim kount As Integer
        Dim dds_item(e.Row.Cells.Count) As
data_dictionary               ' user control
        Dim lbl_temp As New Label

        If Not (e.Row Is Nothing) And e.Row.RowType =
DataControlRowType.Header Then
            For Each cell As TableCell In e.Row.Cells
                If e.Row.Cells.GetCellIndex(cell) >=
dds_descriptions.Count Then
                    dds_descriptions.Add("")
                End If
                kount = e.Row.Cells.GetCellIndex(cell)
                dds_item(kount) = New data_dictionary
                dds_item(kount).data_description =
dds_descriptions(kount)
                If cell.HasControls Then
                    '  put a directional sort arrow on the header
                    Dim button As LinkButton =
DirectCast(cell.Controls(0), LinkButton)
                    If Not (button Is Nothing) Then
                        Dim image As Image = New Image
                        If gvw_data.SortExpression <>
button.CommandArgument Then
                            image.ImageUrl = "http://b4/_style/
noarrow.gif"
                        Else
                            If gvw_data.SortDirection =
SortDirection.Ascending Then
                                image.ImageUrl = "http://b4/_style/
uparrow.gif"
                            Else
                                image.ImageUrl = "http://b4/_style/
downarrow.gif"
                            End If
                        End If
                        If dds_item(kount).data_description <> "" Then
                            cell.Controls.Add(dds_item(kount))
                            cell.Controls.Add(image)
                        End If
                    End If
                Else
                    If dds_item(kount).data_description <> "" Then
         ' heres where the problem occurs
                        lbl_temp.Text = cell.Text
                        cell.Controls.Add(lbl_temp)
                        cell.Controls.Add(dds_item(kount))
                    End If
                End If
            Next
        End If

    End Sub

The problem I have, is that the 'cell.Controls.Add(dds_item(kount))'
seems to overwrite the 'cell.Controls.Add(lbl_temp)', and I get left
with no Column header.

Ideas?

Cheers.
 
D

DaveyP

I have a user control (called data_dictionary) which I need to add
into the header text of a datagrid. I'm doing this by adding the
control in the RowCreated event as follows:

dds_descriptions is an arraylist of strings. data_dictionary is the
user control

Code:
    Sub gvw_data_RowCreated(ByVal sender As Object, ByVal e As
GridViewRowEventArgs)

        Dim kount As Integer
        Dim dds_item(e.Row.Cells.Count) As
data_dictionary               ' user control
        Dim lbl_temp As New Label

        If Not (e.Row Is Nothing) And e.Row.RowType =
DataControlRowType.Header Then
            For Each cell As TableCell In e.Row.Cells
                If e.Row.Cells.GetCellIndex(cell) >=
dds_descriptions.Count Then
                    dds_descriptions.Add("")
                End If
                kount = e.Row.Cells.GetCellIndex(cell)
                dds_item(kount) = New data_dictionary
                dds_item(kount).data_description =
dds_descriptions(kount)
                If cell.HasControls Then
                    '  put a directional sort arrow on the header
                    Dim button As LinkButton =
DirectCast(cell.Controls(0), LinkButton)
                    If Not (button Is Nothing) Then
                        Dim image As Image = New Image
                        If gvw_data.SortExpression <>
button.CommandArgument Then
                            image.ImageUrl = "http://b4/_style/
noarrow.gif"
                        Else
                            If gvw_data.SortDirection =
SortDirection.Ascending Then
                                image.ImageUrl = "http://b4/_style/
uparrow.gif"
                            Else
                                image.ImageUrl = "http://b4/_style/
downarrow.gif"
                            End If
                        End If
                        If dds_item(kount).data_description <> "" Then
                            cell.Controls.Add(dds_item(kount))
                            cell.Controls.Add(image)
                        End If
                    End If
                Else
                    If dds_item(kount).data_description <> "" Then
         ' heres where the problem occurs
                        lbl_temp.Text = cell.Text
                        cell.Controls.Add(lbl_temp)
                        cell.Controls.Add(dds_item(kount))
                    End If
                End If
            Next
        End If

    End Sub

The problem I have, is that the 'cell.Controls.Add(dds_item(kount))'
seems to overwrite the 'cell.Controls.Add(lbl_temp)', and I get left
with no Column header.

Ideas?

Cheers.

bump.
 

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,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top