views:

32

answers:

2

I need to have a grid on one of my webpages that will be used to enter budget information. I was planning on using a gridview, but I am open to other ideas if something else will fit my needs better. I need the following functionality in my grid:

  1. All cells are in edit mode as soon as the page loads
  2. Need a footer row at the bottom to calculate totals for particular columns

I looked around for this functionality in the gridview for a bit but didn't have any luck. Any links or suggestions on how to do the two items above in a gridview would be greatly appreciated.

NOTE: I'm using Visual Studio 2008

+1  A: 

IMO you are going to be much better off coding this yourself using a ListView. You can look into the DataBound() and ItemDataBound() events. The GridView does not come with the functionality built in.

OTOH, Matt Dotson has a blog post describing how to build a GridView with all rows in edit mode.

Matthew Jones
Alright so if i used the ListView method would I just have an item template that was made up of textboxes for each column? How hard is it to access those textboxes to save the values back to the database?
Abe Miessler
A: 

Totals in the footer can be applied using a combination of javascript executed on each data change and form load AND dynamically adding textboxes or labels to the footer via the GridView's RowDataBound event. For example,

// Create textboxes in footer to hold hours totals
if (e.Row.RowType == DataControlRowType.Footer)
{
    e.Row.CssClass = "wgv-ft";

    for (int i = 0; i < NumHoursTextBoxes; ++i)
    {
        var tb = new TextBox();
        tb.ID = String.Format("Hours{0}TotalTextBox", i);
        tb.CssClass = "total";
        tb.Enabled = false;
        e.Row.Cells[FirstHoursTextBoxIndex + i].Controls.Add(tb);
    }
}

Rather than using the built-in edit functionality (EditItemTemplates) which the GridView offers, you might want to just use the ItemTemplates and always show an editable textboxes or other controls. I've used this technique. You can still take advantage of validators and the core ASP.NET control set, but you do have to write quite a bit of javascript to manage updates to the totals.

I hope this helps. Best of luck.

Ben Griswold