?
Solved

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

Posted on 2010-11-10
14
Medium Priority
?
1,004 Views
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
0
Comment
Question by:jhacharya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 6
14 Comments
 
LVL 3

Assisted Solution

by:Epitel0920
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;
Gridview.DataBind();
0
 
LVL 2

Author Comment

by:jhacharya
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.

0
 
LVL 3

Assisted Solution

by:Epitel0920
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:
http://blogs.msdn.com/b/mattdotson/archive/2005/11/09/real-world-gridview-bulk-editing.aspx
0
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!

 
LVL 2

Author Comment

by:jhacharya
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"

            TransposeDataTable
                    (original
                    , 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.

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


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

            MACDGStr.BuildWebGridViewStructure
               ( AllColumnsAvailable
               , ShowHideGridViewColDictionary
               , TextHeadingNameGridViewDictionary
               , ColumnWidthGridViewDictionary
               , ColumnFormatGridViewDictionary
               , ColumnOrderGridViewDictionary
               , GridView1);
           

//I then bind the data table "transposed to the GridView1"          
            MACDGStr.BindDataTableWebToGridView
                        (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
0
 
LVL 3

Assisted Solution

by:Epitel0920
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=""
                        OnRowUpdating="EditableGridView1_RowUpdating"
                        onrowdatabound="EditableGrid1_RowDataBound" CellPadding="0"
                        CellSpacing="0" Width="100%" EnableViewState="False">
                        <Columns>
                            <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" />
                        </Columns>
                    </rwg:bulkeditgridview>

Then you can use it as a regular gridview except all the columns/rows are always editable.
0
 
LVL 2

Author Comment

by:jhacharya
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 ...

0
 
LVL 3

Assisted Solution

by:Epitel0920
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..
0
 
LVL 2

Author Comment

by:jhacharya
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  ...
0
 
LVL 2

Author Comment

by:jhacharya
ID: 34146355
I am still working through the problem ...
0
 
LVL 3

Assisted Solution

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

Author Comment

by:jhacharya
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">
             </rwg:BulkEditGridView>
           
        <asp:GridView ID="GridView3" runat="server"
            onselectedindexchanged="GridView1_SelectedIndexChanged"
            OnRowCommand="GridView2_RowCommand">
        </asp:GridView>
       

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"
            onselectedindexchanged="GridView1_SelectedIndexChanged"
            OnRowCommand="GridView2_RowCommand">
        </asp:GridView>


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?






0
 
LVL 3

Accepted Solution

by:
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">
<controls>
     <add assembly="RealWorld.Grids" namespace="RealWorld.Grids" tagPrefix="rwg"/>
</controls>
</pages>

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.
0
 
LVL 2

Author Comment

by:jhacharya
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 ....
0
 
LVL 2

Author Closing Comment

by:jhacharya
ID: 34239513
excellent help and gave me good direction throughout ..
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

752 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