Adding a new row between rows

Hi to all. I'm trying to do a sort of SubReport. At this moment I have This Code made. It verifies if the column is equal it will erase it's text. What I would like to do now is if the Cell is not Equal then it will create a row with a label that says Sub Report. I tried some code but it inserts the row at the end. Can any one help me?

protected void gridDefectReport_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowIndex > 0)
        {
            DataRow dr = dtReport.Rows[e.Row.RowIndex - 1];
            if (dr[0].Equals(e.Row.Cells[0].Text))
            {
                e.Row.Cells[0].Text = "";

            }
            else if (!dr[0].Equals(e.Row.Cells[0].Text))
            {

            }
        }
    }

0
torrea21
3/5/2009 7:01:31 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

9 Replies
1129 Views

Similar Articles

[PageSpeed] 44

Hi

Here how to create a new row in code behind!

I hope it what you want!
I hope i convert my code right i did't in vb and translate in C#

 In aspx :
 

<asp:Table BorderWidth="1" ID="Table1" runat="server">
    <asp:TableRow>
        <asp:TableCell>test 1</asp:TableCell>
    </asp:TableRow>
    <asp:TableRow>
        <asp:TableCell>test 2</asp:TableCell>
    </asp:TableRow>
    </asp:Table>
 In code behind!
'Insert new row with the text you want! 
var newRow = new TableRow(); 
var newCell = new TableCell(); 

newCell.Text == "xxxx"
newCell.Width = "50"
newCell.Font.Size = 10
newRow.Cells.Add(newCell)
Table1.Rows.Add(newRow)
 
 
If this post is answer of your question then don't forgot to Click Mark As Answer
0
lucsky8
3/5/2009 8:14:32 PM

THe code you provide me is not working. It give me some errors. I changed the c# version 3.0 code to 2.0 but it gave me some errors

 

0
torrea21
3/5/2009 8:37:25 PM

 Have you looked into using a SqlDataAdapter and DataSet to create an in-memory DataTable to add temp rows to?  That might be something to check out if you haven't already...

 

http://msdn.microsoft.com/en-us/library/system.data.dataset.aspx

0
ppalubinski
3/5/2009 9:58:24 PM

I tried that approach without success. Anyone have use the GriedViewHelperClass?

0
torrea21
3/6/2009 12:34:25 PM

Hi here the code in vb

it working for me!

Dim newRow = New TableRow

Dim newCell = New TableCell

newCell.Text = "xxxx"

newCell.Width = "50"

newCell.Font.Size = 10

newRow.Cells.Add(newCell)

Table1.Rows.Add(newRow)

 

Can you post your code


If this post is answer of your question then don't forgot to Click Mark As Answer
0
lucsky8
3/6/2009 2:17:31 PM

that is created outside the Gridview. I want it in between the gridview rows, presenting subtotals.

0
torrea21
3/6/2009 2:46:27 PM

Hi,

 Sorry i am nouse to C# put i just convert it end test it and it working in C#

use this :

 

var newRow = new TableRow();
            var newCell = new TableCell();

            newCell.Text = "yes";
            newCell.Width = 50;

            newRow.Cells.Add(newCell);

            Table1.Rows.Add(newRow);
 
If this post is answer of your question then don't forgot to Click Mark As Answer
0
lucsky8
3/6/2009 2:53:45 PM

This is my Code:

protected void gridReport_DataBound(object sender, EventArgs e)
    {
        const int QTYIndex = 1;
        object sum;
        GridViewRow row = (sender as GridView).FooterRow;

        if (row != null)
        {
            DataTable Table = (sender as GridView).DataSource as DataTable;
            sum = Table.Compute("Sum(QTY)", "");
            row.Cells[QTYIndex].Text = sum.ToString();
            row.Cells[0].Text = "Sum of Quantity:";
            row.Cells[0].HorizontalAlign = HorizontalAlign.Right;
        }
    }

    protected void gridReport_RowDataBound(object sender, GridViewRowEventArgs e)
    {

       if (e.Row.RowIndex > 0)
        {
            DataRow dr = dtReport.Rows[e.Row.RowIndex - 1];
            if (dr[0].Equals(e.Row.Cells[0].Text))
            {
                e.Row.Cells[0].Text = "";
                if (RowCounter == dtReport.Rows.Count)
                {
                    // Sub Report Final Line
                }
            }
            else if (!dr[0].Equals(e.Row.Cells[0].Text))
            {
                //Sub Report Between Lines
            }
        }
        RowCounter++;
    }

0
torrea21
3/6/2009 2:54:56 PM

To add new row in gridview try :
Don't forget
ondatabound="GridView1_DataBound"

 

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
        DataKeyNames="intAnneeScolaire" DataSourceID="SqlDataSource1"  ondatabound="GridView1_DataBound">
        <Columns>
	your code
            </Columns>
    </asp:GridView>
  
 protected void GridView1_DataBound(object sender, EventArgs e)

        {


            GridViewRow row = new GridViewRow(0,0,DataControlRowType.DataRow,DataControlRowState.Alternate);

            foreach (DataControlField field in GridView1.Columns)
            {
                TableCell cell = new TableCell();
                cell.Text = "Sub Report";
                row.Cells.Add(cell);
            }

            GridView1.Controls[0].Controls.AddAt(2, row);

        }

If this post is answer of your question then don't forgot to Click Mark As Answer
0
lucsky8
3/6/2009 3:23:42 PM
Reply:

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

adding / deleting table rows, and accessing controls within added rows
Hi everyone,I would like to know what is a good and simple way to achieve this using asp.net.  Basically i would like the ability to add and delete rows, preferably table rows.  Against each row is its delete button, hitting it will delete the corresponding row.  There is only 1 Add button to add a new row.  In each row, there are say 2 textboxes.  When i hit, say a calculate button, i wish to be able to access all the available textboxes in all the available rows in the event handler, and say just output a sum.If GridView is suggested, could you please explain why i...

adding a blank header row /row above the header row
is it possible to add a blank row above the header row in gridview for adding some links and buttons the links will respond to thae data in the grid and the buttons are for login / regisration etc....  if yes how it can be done or how do i achieve it. Its better that u create a table with a single row with columns matching the GridView columns. Set the table width same as the GridView width. This will make the GridView Look as if there is a row above its header.Please do not forget to click Mark As Answer on the post that helped you. Regards,Iam Srikanth Reddy....

basket adding a new row rather than updating the same row
 Hi, I hope someone can help me?  I have an add to basket application which does not quite work, in that when try to add the same item to the basket, rather than updating the same row it adds another row instead.  I am using a session datagrid type basket from code I incorporated after looking the the sitepoint website  http://www.sitepoint.com/article/net-shopping-cart-datatables, though I know its dated it seems to be ok.I think the problem may lie with the following bit of code, in that it is not updating the table correctly somehow but not sure from this point, a...

Adding row (one at a time) in gridview on a button click. And cells of added row should contain controls like DROPDOWN LIST or TEXT BOX.
Dear Friends, I am in great need for the solution/hints/guidance of my requirement, if anyone can help with.  Let me explain what I need."I need a Gridview control on a webpage having following 5 columns/fields.     Column 1: It just has a "+" button in its header only (other cells for this column is empty)    Column 2: The Column header here is "FIELD" and  it should contain dropdown list (which is populated from some database)    Column 3: The Column header here is "Operator" and  it should ...

adding new rows to the repeater control
Dear ASP.NET Programmers, Here's my problem: I have a page (as usual :), in which I'm going to display invoices in a repeater control. I am binding data to the repeater control (ID: repHospCosts) without any problems. I have also a button on the page, I am going to add a new datarow programmatically and display it when pressed. Unfortunately, I cannot refer to the dataset in the event handler of the button (or at least I think so). I get the following error: Object reference not set to an instance of an object. drow = dtable.NewRow Below is the code: Dim dtable As DataTableDim drow As Dat...

Adding a new row of controls on button click
Hi all,In a site I'm currently writing, I have a page in which users can add entries to the database.  The entries are very simple, consisting of selections from three drop down lists.In order to make it easier on the user, I would prefer to allow multiple entries to be created on the same page.  To keep the page clutter down, I want the user to be able to click on a button to add another row for entry creation on the same page.For a visual example of what I mean, check out this link. At the very bottom under "advanced search using boolean charts" is exactly what I wa...

Adding Dynamic row to Row
I have written the following code in javascript. This code is working fine in FireFox but not in IE 7.Need help so that it should  also work fine in IE7.Thanks.  var repeater= document.getElementById('<%=repeater.ClientID %>');        var obj = result;        var newRow = document.createElement("tr");        var newCell = document.createElement("td");        var ctrlInputHid = document.createElement("input...

First Row, Next Row, Prior Row, Last Row
I have a SQL Anywhere 7.0 Database, have a table Product_detail which contains Column Name Datatype width Null Default batch_id char(10) No None prod_id Integer No None employee_id Integer No None quantity Integer No None price Numeric (14, 2) No None Its primary key is batch_id I have a Freeform Datawindow with this table I want to provide the first row, next row, prior row and last row Ho...

Dynamically adding a new row & assigning total values of the existing row columns in a grid view
Hi All, My web application has a aspx(C#) file which shows the report data in a  grid view.  the grid has first two coulmns fixed and columns 3 & onwards are dynamically generated. What I want - A new row at the end of grid should be added dynamically which should display the total of each column 3 onwards. Any help would be much appreciated.  Thanks, Srain.     http://aspalliance.com/782 If you need three dynamic columns total to be displayed then declare three Global valibales and In RowDataBound event try like this  If (e.Row.RowTy...

Adding a new row to a table for each new user
I have a table using SQL server, which has 4 fields DetailsID - int UserID linked to the UserID in aspnet_users table FirstName Surname I would like to automatically add a line into this table when a new user is created, so that the table can be updated by the user, with an edit only DetailView.  Could someone tell me how to automatically add a new row to a table, when a new user is created? Thanks in advance How are you creating a new user?  If you are using the CreateUserWizard to create a new user, then you can use the CreatedUser event of the Wizard to create a new row...

Scroll row by row in a datawindow control
Hi. I have a tabular datawindow object with one group and all my data is displayed in the header group and the detail band is not visible. when i run my application and i want to scroll the data the datawindow control scrolls the data page by page and i need it row by row. How can i do this? thank you in advanced You will have to move your data into the detail band. "Row" in datawindow is contents of the detail band. Igor "Fernando Pe�a" <Fernando_Pe0xL1A4za> wrote in message news:943886BF87C590640077873785256A65.0077874785256A65@webforums.....

How to add new rows in the form of rows
Hi, I can able to insert,delete and update record in gridview but cannot able to insert any new rows in the gird. In windows application we can insert new records(using DataGridView) into the database but not in web page. How to insert the records in gridview like control. Please tell me how to insert records in database in the form of rows. I mean i want to enter 20 records at one time.   Thanks.   Regards ArshadPlease Mark as Answer if the post is helpful to you. hi, Have you set the property AllowUserToAddRows=True; for the datagridview?????  If you are us...

New row in datagrid: Old values are overwritten instead of a new row appears
First post from a not so experienced VS.NET/VB programmer I am writing a short piece of code that allows users of the program to enter some data in textboxes and then by clicking on a button, allow them to add the information they put in the textboxes to a datagrid. The first time they press this button, it shows perfectly in the datagrid on the form, but the 2nd time it only updates the first row instead of adding a new row.By doing some searches on Google, I found out that I am not using the right code, but I can't find how to do it correctly. I hope to get an answer here.Below you see...

Web resources about - Adding a new row between rows - asp.net.presentation-controls

Gun Activists Claim Obama Celebrated 'Holy Grail' Of Planned Parenthood Shooting
In an interview on Sunday with Mark Walters of Armed American Radio, the Second Amendment Foundation’s Alan Gottlieb claimed that the deadly ...

Mark Hamill goes undercover and meets unsuspecting Star Wars fans
Mark Hamill has accepted a new role: Stormtrooper. In order to raise awareness for Force for Change , a charitable organization from Star Wars ...

Report: YouTube Red is seeking streaming rights for movies and TV shows
LOS ANGELES — Looks like YouTubers may not be the only ones who will have content available on the streaming service YouTube Red The Google-owned ...

UK bombs Syrian oil field after MPs vote for strikes
Britain joined the US-led bombing campaign over Syria on Thursday, hitting an oil field held by Islamic State jihadists just hours after a decisive ...

Meet the 15-year-old creator of "The Last Message Received" Tumblr
Emily Trunko, 15, lives in Copley, Ohio. She is the creator of The Last Message Received , a Tumblr that posts screenshots of final text messages ...

Easter Eggs and Hidden References in the New ‘Batman v Superman: Dawn of Justice’ Trailer
Mr. Sunday Movies points out some of the easter eggs and hidden references in the new trailer for the upcoming film Batman v Superman: Dawn of ...

Google makes big clean energy purchase to power data centers
Powering Google's online empire takes a lot of energy, and the company wants to use all clean sources to run its data centers by 2025. The company ...

Hawaii Supreme Court pulls construction permit for one of the world's largest telescopes
A long-awaited Hawaii Supreme Court ruling Wednesday invalidating a construction permit for what would be one of the world's largest telescopes ...

Pentagon chief to military: Open all combat jobs to women
WASHINGTON (AP) — Defense Secretary Ash Carter on Thursday ordered the military to open all combat jobs to women, rebuffing requests by the Marine ...

Apple takes the Swift programming language open source
First promised back at WWDC in June , Apple has just taken its Swift programming language open source with the introduction of a new site – swift.org ...

Resources last updated: 12/3/2015 7:13:42 PM