Solved

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

Posted on 2010-11-10
14
994 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
 
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now