gridview formatting - can you add blank rows

Posted on 2006-04-06
Last Modified: 2012-08-13

I don't know much about the internal structure of data controls. How would you go about adding a blank row to a gridview to put some text in?

Thanks a lot
Question by:andieje
    LVL 12

    Accepted Solution


    if you are using a gridview - you have to bind it to a data source to display the data...
    can add a new row to the DataTable and then bind the grid to table, then set the gridview editindex to the new row,
          // Open Connection
          // New DataSet
          DataSet dbSet = new DataSet();
          // Populate DataSet with data
          dbAdapt.Fill(dbSet, "tblFile");

          // Get reference to our table
          DataTable dbTable = dbSet.Tables["tblFile"];

          // Create new row
          DataRow dbRow = dbTable.NewRow();

          // Store data in the row
          dbRow["FileName"] = "";
          dbRow["FileSize"] = '";

          // Add row back to table
                    from here set the datasource   - idea is right just syntax errors
                    gridview.datasource = dbTable.defaultview
                    gridview.editindex = the index of the new row

    Author Comment

    You're kidding me??? Is this the easiest way to add a text row to a gridview? wow
    LVL 12

    Expert Comment


    is there a primary key value in the datagrid - does the new row need a primary key or auto increment index value? my way will make sure that if there is one then the new row will contain the new index, otherwise if it is not required then there is more could be a few other ways to do it.

    Author Comment


    I don't think i phrased my question very well. I don't mean a new row in the gridview for containing actual database data.

    I meant, can you add a row to the gridview that is purely for display purposes, for example to comment on the dtaa that is being displayed.

    My question is more about formatting the gridview control. I would like to be able to add extra blank spaces between rows of data where I can add information of my own, nothing to do with the underlying data source. In the spaces I would like to add titles/subtitles/comments.

    Thanks a lot, andrea
    LVL 12

    Expert Comment

    hi andrea,

    you could possibly do it with this javascript eg add cells to the table with client side scripting, I am not that clued up on javascripting but it would be a good idea to get upto spead on it as microsoft are going to push a technology called ajax which is basically with java doing client side stuff to minimise server requests and give the user a similiar experience to using a windows app, eg more functionality and more responsive...

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now