473,472 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to add panel as a first row in gridview..?

1 New Member
How do you add panel as a first row in GridView?

I have tried with the below example,but am getting panel in 2nd row..but i want in 1st row.kindly help me
Expand|Select|Wrap|Line Numbers
  1. protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  2.     {
  3.         if (e.Row.RowType == DataControlRowType.DataRow)
  4.         {
  5.             TableCell tCell = new TableCell();
  6.             // create image 
  7.             //Panel p = new Panel();
  8.             //p.GroupingText = "Panel";
  9.             //p.BorderWidth = 2;
  10.  
  11.             Image img = new Image();
  12.             img.ImageUrl = "Page.jpg";
  13.              //add the image to the cell
  14.             tCell.Controls.Add(img);
  15.  
  16.             GridView gView = (GridView)sender;
  17.             // set the colspan to occupy the other cells in the row
  18.             int colSpan = gView.Columns.Count;
  19.             tCell.Attributes["ColSpan"] = colSpan.ToString();
  20.  
  21.             GridViewRow gRow = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
  22.             // add the cells to the gridviewrow
  23.             gRow.Cells.Add(tCell);
  24.  
  25.             Table tbl = (Table)e.Row.Parent;
  26.  
  27.             // set the pagesize initially to the pagecount/2
  28.             // in our case it is 10/2 = 5. So the first image will 
  29.             // displayed after the 5th row.
  30.             if (pgSize == 0)
  31.                 pgSize = GridView1.PageCount /2;
  32.  
  33.             // This step is performed so that we can display the image only after every 
  34.             // 5, 15, 25 ,35 rows and so on ...
  35.             // The logic is not perfect but will give you the idea
  36.             if (Convert.ToDouble(e.Row.DataItemIndex + 1) / Convert.ToDouble(pgSize) == 1.0)
  37.             {
  38.                 tbl.Controls.AddAt(gView.Controls[0].Controls.Count, gRow);
  39.                 // add 10 to the pgsize so that the image can be displayed
  40.                 // at rows 5, 15, 25 and so on..
  41.                 pgSize = pgSize + 10;
  42.             }
  43.         }
  44.     }
Mar 9 '12 #1
1 3801
Frinavale
9,735 Recognized Expert Moderator Expert
GridViews are controls that display data in a tabular format.
In other words, GridViews display the data that it is bound to in a table format (with rows and columns).

If you need to display a panel with some controls in it, then I suggest you do so above the GridView. It does not make sense to try and do this within the GridView.

-Frinny
Mar 12 '12 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Anders Eriksson | last post by:
Hello! How do I add a panel and get the already existing controls to be included in the panel? The only way I have made it work if I create the panel first and then add the other controls....
1
by: Edward | last post by:
On mine ASP 2.0 page I've two gridviews. The second depends on the selected value of the first one. Everything is working ok. When selecting a row from the first, the second gridview is displaying...
2
by: Loading name... | last post by:
Hey asp.net 2.0 I have a GridView on my webpage. This GridView's datasource is a SqlDataSource. The SqlDataSource returns 3 columns. Here is my problem: My GridView consist of 3 columns...
2
by: Darren Carter | last post by:
Hi, I have mutliple asp:Panel controls on a single page, each with a default button defined (each default button resides within its respective asp:Panel). All validation controls and buttons...
2
by: sck10 | last post by:
Hello, I have a web page that has a GridView and a FormView, each in its own panel. The GridView shows a list of records in a database. When a row in the GridView is selected the FormView...
3
by: Carlos | last post by:
Hi all, I would like to know what is the most efficient way to redirect a gridview containing data to another page. It is kind of confirming an order which just needs to be re-displayed. Can...
0
by: titia111 | last post by:
This is my second post. Can anyone help? I am using nested gridviews, and they are pulling the data correctly but I am having difficulty formatting the results. I need to insert a line break...
1
by: jaydev | last post by:
Hi, Is it possible to make the gridview editable on mouse click and save the changes on tab out? like the todo list in google widget? ...
0
by: AdonisL81 | last post by:
Hello, I am new to .NET I am having trouble with a asp update panel and Gridview. The Gridview control is inside the update panel and I am trying to have the gridview update from a form button....
1
by: visweswaran2830 | last post by:
Hi, let consider, I have two gridview. In that, I have selected one row on first girview and based on that value I am going to generate second gridview, and then I doing some manipulation on...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.