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
Solved

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

Posted on 2010-11-10
14
1,000 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
  • 8
  • 6
14 Comments
 
LVL 3

Assisted Solution

by:Epitel0920
Epitel0920 earned 500 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 500 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 500 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 500 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 500 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

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 is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

839 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