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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhukar a
    New Member
    • Mar 2012
    • 1

    #1

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

    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
    Code:
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                TableCell tCell = new TableCell();
                // create image 
                //Panel p = new Panel();
                //p.GroupingText = "Panel";
                //p.BorderWidth = 2;
    
                Image img = new Image();
                img.ImageUrl = "Page.jpg";
                 //add the image to the cell
                tCell.Controls.Add(img);
    
                GridView gView = (GridView)sender;
                // set the colspan to occupy the other cells in the row
                int colSpan = gView.Columns.Count;
                tCell.Attributes["ColSpan"] = colSpan.ToString();
    
                GridViewRow gRow = new GridViewRow(-1, -1, DataControlRowType.DataRow, DataControlRowState.Normal);
                // add the cells to the gridviewrow
                gRow.Cells.Add(tCell);
    
                Table tbl = (Table)e.Row.Parent;
    
                // set the pagesize initially to the pagecount/2
                // in our case it is 10/2 = 5. So the first image will 
                // displayed after the 5th row.
                if (pgSize == 0)
                    pgSize = GridView1.PageCount /2;
    
                // This step is performed so that we can display the image only after every 
                // 5, 15, 25 ,35 rows and so on ...
                // The logic is not perfect but will give you the idea
                if (Convert.ToDouble(e.Row.DataItemIndex + 1) / Convert.ToDouble(pgSize) == 1.0)
                {
                    tbl.Controls.AddAt(gView.Controls[0].Controls.Count, gRow);
                    // add 10 to the pgsize so that the image can be displayed
                    // at rows 5, 15, 25 and so on..
                    pgSize = pgSize + 10;
                }
            }
        }
    Last edited by Frinavale; Mar 12 '12, 04:36 PM. Reason: Added the question asked in the thread title to the thread.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    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

    Comment

    Working...