Home All Groups Group Topic Archive Search About
Author
26 Mar 2006 10:45 PM
David D.
Can someone easily tell me how to change what the Gridview renders for the
table to get a colspan attribute on selected rows of the table? 

In my GridView1_RowDataBound event I am checking the contents of a
particular cell: 

If e.Row.Cells(2) = "Something" Then
   I want to merge columns 2 and 3 into one (<td colspan=2>)
End If

Thanks,  --David

Author
26 Mar 2006 11:07 PM
Phillip Williams
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.Cells(0).Text.Equals("267-41-2394") Then
            'append the content of cell # 2 to cell #1
            e.Row.Cells(1).Text += " " & e.Row.Cells(2).Text
            'set the columnspan
            e.Row.Cells(1).ColumnSpan = "2"
            'remove the second cell
            e.Row.Cells.Remove(e.Row.Cells(2))

        End If
    End Sub
Show quoteHide quote
"David D." wrote:

> Can someone easily tell me how to change what the Gridview renders for the
> table to get a colspan attribute on selected rows of the table? 
>
> In my GridView1_RowDataBound event I am checking the contents of a
> particular cell: 
>
> If e.Row.Cells(2) = "Something" Then
>    I want to merge columns 2 and 3 into one (<td colspan=2>)
> End If
>
> Thanks,  --David
Author
7 Apr 2006 11:29 PM
David D.
Great!  It was the e.Row.Cells.Remove(e.Row.Cells(2)) that was the secret. 
Thanks so much!

Show quoteHide quote
"Phillip Williams" wrote:

>
>  Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
>         If e.Row.Cells(0).Text.Equals("267-41-2394") Then
>             'append the content of cell # 2 to cell #1
>             e.Row.Cells(1).Text += " " & e.Row.Cells(2).Text
>             'set the columnspan
>             e.Row.Cells(1).ColumnSpan = "2"
>             'remove the second cell
>             e.Row.Cells.Remove(e.Row.Cells(2))
>
>         End If
>     End Sub
> --
> HTH,
> Phillip Williams
> http://www.societopia.net
> http://www.webswapp.com
>
>
> "David D." wrote:
>
> > Can someone easily tell me how to change what the Gridview renders for the
> > table to get a colspan attribute on selected rows of the table? 
> >
> > In my GridView1_RowDataBound event I am checking the contents of a
> > particular cell: 
> >
> > If e.Row.Cells(2) = "Something" Then
> >    I want to merge columns 2 and 3 into one (<td colspan=2>)
> > End If
> >
> > Thanks,  --David