Improve company productivity with a Business Account.Sign Up


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

Posted on 2010-11-10
Medium Priority
Last Modified: 2012-05-10
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
Question by:Jayesh Acharya
  • 8
  • 6

Assisted Solution

Epitel0920 earned 2000 total points
ID: 34104262
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;

Author Comment

by:Jayesh Acharya
ID: 34104611
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.


Assisted Solution

Epitel0920 earned 2000 total points
ID: 34104672
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:
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Comment

by:Jayesh Acharya
ID: 34105930
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

Assisted Solution

Epitel0920 earned 2000 total points
ID: 34106275
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.

Author Comment

by:Jayesh Acharya
ID: 34106898
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 ...


Assisted Solution

Epitel0920 earned 2000 total points
ID: 34106939
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..

Author Comment

by:Jayesh Acharya
ID: 34114007
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  ...

Author Comment

by:Jayesh Acharya
ID: 34146355
I am still working through the problem ...

Assisted Solution

Epitel0920 earned 2000 total points
ID: 34146744
Let me know if you need more help.

Author Comment

by:Jayesh Acharya
ID: 34200908
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?


Accepted Solution

Epitel0920 earned 2000 total points
ID: 34201036
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.

Author Comment

by:Jayesh Acharya
ID: 34239380
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 ....

Author Closing Comment

by:Jayesh Acharya
ID: 34239513
excellent help and gave me good direction throughout ..

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
From store locators to asset tracking and route optimization, learn how leading companies are using Google Maps APIs throughout the customer journey to increase checkout conversions, boost user engagement, and optimize order fulfillment. Powered …

595 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