[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 700
  • Last Modified:

gridview formatting - can you add blank rows

Hi

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
andrea
0
andieje
Asked:
andieje
  • 3
  • 2
1 Solution
 
deanvanrooyenCommented:
hi,

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,
eg
      // Open Connection
      dbConn.Open();
                              
      // 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
      dbTable.Rows.Add(dbRow);
               
                from here set the datasource   - idea is right just syntax errors
                gridview.datasource = dbTable.defaultview
                gridview.databind()
                gridview.editindex = the index of the new row
0
 
andiejeAuthor Commented:
You're kidding me??? Is this the easiest way to add a text row to a gridview? wow
0
 
deanvanrooyenCommented:
hi,

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.
0
 
andiejeAuthor Commented:
Hi

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
0
 
deanvanrooyenCommented:
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 asp.net 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...
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now