Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 25th, 2007, 02:51 PM
Authorized User
 
Join Date: Jun 2006
Location: Chelmsford, MA, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default Gridview Rowspan and ColumnSpan

I'm trying to do Row and Col Spans in Gridview.
But Gridview is not doing rowspans for following format.

Sample HTML:

<table>
  <tr style='color:White;background-color:#6B949E;font-weight:bold;'>
   <td rowspan=2 valign="top" width="27%"><B>a</B></td>
   <td rowspan=2 valign="top"><B>b</B></td>
   <td colspan=2 align=center><B>c</B></td>
   <td rowspan=2 valign="top"><B>d</B></td>
   <td colspan=3 align=center><B>e</B></td>
  </tr>
  <tr style='color:White;background-color:#6B949E;font-weight:bold;'>
   <td><B>c 1</B></td>
   <td><B>c 2</B></td>
   <td><B>e 1</B></td>
   <td><B>e 2</B></td>
   <td><B>e 3</B></td>
  </tr>
  <tr><td><a href="">1</a></td><td>Open</td><td><a href="?t=1">Open</a></td><td><a href="?t=2">Open</a></td><td><a href="?t=5">Open</a></td><td><a href="?t=4">Open</a></td><td><a href="?t=6">Open</a></td><td><a href="?t=3">Open</a></td></tr>
  <tr><td><a href="">2</a></td><td>Open</td><td><a href="?t=1">Open</a></td><td><a href="?t=2">Open</a></td><td><a href="?t=5">Open</a></td><td><a href="?t=4">Open</a></td><td><a href="?t=6">Open</a></td><td><a href="?t=3">Open</a></td></tr>
 </table>


Gridview Code:
      <asp:GridView Width="100%" ID="Gv" HeaderStyle-Font-Bold="True" runat="Server"
       AutoGenerateColumns="False" AllowSorting="True" CellSpacing="0" CellPadding="1"
       PageSize="20" BorderWidth="1" GridLines="Both" AllowPaging="True" >
       <HeaderStyle ForeColor="#FFFFFF" BackColor="#6b949e" CssClass="gvTableHeadersLeftAlign" />
       <AlternatingRowStyle BackColor="#ececec" />
       <PagerSettings Position="TopAndBottom" PageButtonCount="20" Mode="NumericFirstLast" />
       <PagerStyle HorizontalAlign="Center" />
       <RowStyle HorizontalAlign="Left"/>
        <Columns>
         <asp:BoundField DataField="a" HeaderText="a"/>
         <asp:BoundField DataField="b" HeaderText="b"/>
         <asp:BoundField DataField="c" HeaderText="c"/>
         <asp:BoundField DataField="d" HeaderText="d"/>
         <asp:BoundField DataField="e" HeaderText="e"/>
         <asp:BoundField DataField="f" HeaderText="f"/>
         <asp:BoundField DataField="g" HeaderText="g"/>
         <asp:BoundField DataField="h" HeaderText="h"/>
        </Columns>
       </asp:GridView>

Server side Code:

        If e.Row.RowType = DataControlRowType.Header Then
            Dim gvRow As GridViewRow
            Gv = sender
            gvRow = New GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert)
            gvRow.Cells.Add(GridView_CreateCustomCell("a", 2, 0))
            gvRow.Cells.Add(GridView_CreateCustomCell("b", 2, 0))
            gvRow.Cells.Add(GridView_CreateCustomCell("c", 0, 2))
            gvRow.Cells.Add(GridView_CreateCustomCell("e", 0, 3))
            GvInstitution.Controls(0).Controls.AddAt(0, gvRow)
        End If



Any help appreciated.
__________________
Rams
  #2 (permalink)  
Old June 25th, 2007, 08:12 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

While I haven't worked a whole lot with the grid view itself, the way I used to achieve custom formatting of the ASP.NET 1.1 datagrid control was to handle it inside the ItemCreated event. Inside the handler you can test the datagrid(view) item type. When it's the Header item, you can modify the cells collection of "e.Item" and manipulate as desired.

Here's a short article of using the ItemDataBound event:
http://www.codeproject.com/aspnet/ItemCreated.asp
and the documentation from MSDN:
http://msdn2.microsoft.com/en-us/lib...databound.aspx

Here's the docs on ItemCreated:
http://msdn2.microsoft.com/en-us/lib...emcreated.aspx

An important distinction between ItemDataBound and ItemCreated that isn't well documented is this:

- ItemCreated is called EVERY time the grid is constructed (i.e. on grid data bind as well as on a postback when the grid is being REconstructed even if you don't explicitly do anything to it).

- ItemDataBound is ONLY called when you call the DataBind() method. If you use this event to reformat the control, it will look good after a page hit where the grid is data bound, but not on a non-binding postback.

-Peter
  #3 (permalink)  
Old June 25th, 2007, 08:42 PM
Authorized User
 
Join Date: Jun 2006
Location: Chelmsford, MA, USA.
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, I am writing this in Gridview RowCreated Event. My problem is when i give rowspan =2 then the second header is not row spanning, instead it creates another column.

Rams
  #4 (permalink)  
Old June 25th, 2007, 09:29 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

If you need to customize the layout to a greater extent, you might want to try a less restrictive control such as the repeater. This permits much more control over the item, header, and footer templates.

-Peter
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Filling the gaps of rowspan/colspan sources maikm XSLT 3 August 27th, 2008 03:36 AM
Using Rowspan in datagrid bala24 General .NET 2 February 15th, 2008 03:21 AM
RowSpan not working like I thought MLaGrange ASP.NET 2.0 Basics 0 February 20th, 2006 10:13 AM
RowSpan tgopal Javascript 6 September 28th, 2004 03:35 AM
ROWSPAN PROBLEM saravananedu HTML Code Clinic 3 July 27th, 2004 03:58 AM



All times are GMT -4. The time now is 12:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.