• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1006
  • Last Modified:

System.Web.UI.WebControls.GridView problem editing cells

I have dynamically built a System.Web.UI.WebControls.GridView on my web page which does show all the data I want, The problem now I have is I dont know know how to edit the value in the cell

if someone could give me a quick example that would be great
Jayesh Acharya
Jayesh Acharya
  • 8
  • 6
6 Solutions
GridView.Rows[1].Cells[1].Text = "data";

However I think it would be better if you have some DataTable which you bind to the GridView. Then you can change that and rebind it.

DataTable dt;
dt.Rows[i][j] = 'data';
Gridview.DataSource = dt;
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
I do have a datatable that I build and populate and this is then bound to the gridview,

but when it displays the data, I cant click into the cell, there seems no way of editing the grid from teh webpage

i dont know if there is a setting i need to include to allow me allow me to edit the cell.

Thats harder to do. Gridview only allows RowEditting by default. I actually did something similar a little while ago and I used Real World grids, instead of a regular GridView.
You can get those grids here:
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Jayesh AcharyaTechnichal ConsultantAuthor Commented:
Below is my basic logic

//this code builds me a data table that holds all the data I want, from variouse tables and running
// through variouse Business rules  the table that I use is called "transposed"

                    , transposed
                    , LangR
                    , "US_STRING"
                    , "US_STRING_ID"
                    , "LANGUAGE_CD"
                    , "LANGUAGE_STRING"
                    , "_ID"
                    , "LANGUAGE_MPNG_ID"
                    , false
                    , DBEnv);

// I build a bunch of dictionaries to hold values that I want to change for me
// to be able to build the gridview in teh way I want, i.e. chnage the column positons
// hide columns etc.

                ( AllColumnsAvailable
                , ColumnFormatDictLang()
                , ColumnWidthDictLang()
                , ColumnOrderDictLang()
                , HeaderTextDictLang()
                , HideShowGridViewColDict());

//based on the dictionaries I have built above I then build the gridview "GridView1"

               ( AllColumnsAvailable
               , ShowHideGridViewColDictionary
               , TextHeadingNameGridViewDictionary
               , ColumnWidthGridViewDictionary
               , ColumnFormatGridViewDictionary
               , ColumnOrderGridViewDictionary
               , GridView1);

//I then bind the data table "transposed to the GridView1"          
                        , transposed);

Now this does build me a gridview that shows all the data, but I dont know where in the .cs file I can change the setting of the row to make it editable
and if I could make the row editable how do i get this data to run an insert statement back to the database ..

If at the worst they can have to update a row that will work .. its not ideal becasue I really wanted you to just click the cell and then update that ..

But I am stuck and I am trying to use the real world grids but I am still a novice at this and would need a bit of help
To use RealWorldGrid you need to download the .zip file and open the website, when you build the website in the bin/Debug folder you will have .dll file. Copy it to your project folder and add a reference to it. Also copy RealWorldGrid directory to the project folder.
Then you can declare an instance like so:
<rwg:bulkeditgridview ID="EditableGrid1" AutoGenerateColumns="False"
                        runat="server" EnableInsert="False" SaveButtonID=""
                        onrowdatabound="EditableGrid1_RowDataBound" CellPadding="0"
                        CellSpacing="0" Width="100%" EnableViewState="False">
                            <asp:BoundField HeaderText="A" DataField="A" />
                            <asp:BoundField HeaderText="B" DataField="B" />
                            <asp:BoundField HeaderText="C" DataField="C" />
                            <asp:BoundField HeaderText="D" DataField="D" />
                            <asp:BoundField HeaderText="E" DataField="E" />

Then you can use it as a regular gridview except all the columns/rows are always editable.
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: Unknown server tag 'rwg:bulkeditgridview'.

Source Error:

Line 22:         </asp:GridView>
Line 23:  
Line 24:         <rwg:bulkeditgridview ID="GridView3" AutoGenerateColumns="False"
Line 25:                         runat="server" EnableInsert="False" SaveButtonID=""
Line 26:                         OnRowUpdating="EditableGridView1_RowUpdating"

this fails for me ...

if I take out the code in teh aspx i can get the code to run, but i cant get the object to display ...

Did you add the reference from your project to the RealWorld.Grids.dll?
Can you try adding using RealWorld.Grids; and see if intelisence recognizes it..
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
I did add the code, and while it does compile I now dont get to see the grid at all ...

I am trying to work through the problem, but I think there is enough there  ...
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
I am still working through the problem ...
Let me know if you need more help.
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
I may need to go through this step by step

1st I am just trying to add the gridview to my aspx page

             <rwg:BulkEditGridView ID="EditableGrid" runat="server"
                 EnableInsert="true" ShowFooter="false">
        <asp:GridView ID="GridView3" runat="server"

but c# does not recognise the rwg

I have tried to add the project directly and I also tried add it via the reference ...

so i am really lost ...

I think 1st i need to know how to reference the bulkedit gridview, so that I can 1st try to see if i can just get the data to popultae in the bulk edit gridview ...

in my .aspx file i define the grid like

        <asp:GridView ID="GridView3" runat="server"

in my .aspx.cs file i define the grid

protected global::System.Web.UI.WebControls.GridView GridView3;

I then build a datatable from a dictionary
                // Build the structure of the data table
                foreach (KeyValuePair<string, string> GridColsPair in lv_GridCols)
                    lv_DataTable.Columns.Add(GridColsPair.Key, Type.GetType("System.String"));


can you help me with just to get the RealWorld.Grids.BulkEditGridView to be recognised in the .aspx

becasue rwg doent seem to work ... is there a place i need to define this type of tag?

First you need to add the RealWorld.Grids folder to your solution. Then you should build it.

Then open your web.config. Make sure in the <system.web> section you have something like:
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID" enableEventValidation="false" viewStateEncryptionMode="Never" enableViewStateMac="false" validateRequest="false">
     <add assembly="RealWorld.Grids" namespace="RealWorld.Grids" tagPrefix="rwg"/>

Then go to Property Pages of your main solution.
You should have under References:
Reference Name: RealWorld.Grids.
Type: BIN
Version: Auto Update

Let me know if you don't have those.
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
Brilliant ... works as I would of expected ... the webconfig was the issue, this is a really big help thanks again ...

I am looking at now how to save / update / delete / add data to that grid.

Also, is there a way to have each cell as a drop down list ? if not thats ok , but if there is something simple then that would be great ....
Jayesh AcharyaTechnichal ConsultantAuthor Commented:
excellent help and gave me good direction throughout ..

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now