Results 1 to 7 of 7

Thread: [RESOLVED] Get cell value of DataGrid???

  1. #1

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Resolved [RESOLVED] Get cell value of DataGrid???

    How do I get/set the cell value of a DataGrid like in the image.

    I want to get the text from the textbox in the cell and use it in a save command.

    Here is my current code:
    c#.net Code:
    1. protected void grid_ItemCommand(object source, DataGridCommandEventArgs e)
    2.     {
    3.         // stop editing
    4.         GV.EditItemIndex = -1;
    5.  
    6.         switch (e.CommandName)
    7.         {
    8.             case "Insert":
    9.                 break;
    10.             case "Update":
    11.                 string a = "";
    12.                
    13.               a = e.Item.Cells[1].Text;
    14.                            
    15.                
    16.                 break;
    17.             case "Cancel":
    18.                 EditCommandColumn ecc = (EditCommandColumn)GV.Columns[0];
    19.                 ecc.UpdateText = "Update";
    20.                 break;
    21.             case "Edit":
    22.                 // begin editing
    23.                 GV.EditItemIndex = e.Item.ItemIndex;
    24.                 break;
    25.         }

    That code is returning blank strings. Please help me get my cell values.
    Name:  ASP.jpg
Views: 1676
Size:  31.5 KB

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,597

    Re: Get cell value of DataGrid???

    Is this an asp.net issue?I see simple grid.In asp.net you can use findcontrol to view elements inside a gridview.
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

  3. #3
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Get cell value of DataGrid???

    First up, just to confirm, are you using the DataGrid (which is an older control) or are you using the GridView? Although there are some similarities in the way they do things, they are essentially two very different controls.

    How, and when, are you binding the data into the GridView? It could be that once you hit the Insert command, your DataBinding is happening again, and you are losing the entry that the you have made into the TextBox.

    Gary

  4. #4

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Get cell value of DataGrid???

    I'm using both the DataGrid and the GridView, going through tutorials.
    I have a function which populates a dataset from my db and I just use that as the datasource.

    What I would like to happen is to add the new item(s) to the dataset. I will then write it back to the db at submit.

    My issue was getting the value from that textbox. Without that I can't add anything to my dataset.

    My issue with the gridview, and this is the only issue I have with it at the moment, is that I don't know how to determine on which line I am. I added the "delete" column, but I can not find where to detect the row index on which I clicked the delete link.

    I'm a vb.net programmer and I got this asp.net project which had to be done in C#, so you can imagine what a learning experience this has been. The C# I get, because the syntax and the functions are mostly similar to vb.net, but the asp.net controls threw me totally off track. I'm basically looking for something similar to the DataGridView in vb.net, but as this is webbased I get that things are done differently. I really need to figure out how to add the input text to my dataset and how to delete certain rows in the grid.

    This issue has been holding me back like you wouldn't believe.

  5. #5

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Get cell value of DataGrid???

    Oh I want to add to that, I would prefer to use the GridView.

  6. #6
    ASP.NET Moderator gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: Get cell value of DataGrid???

    I would agree, you should use the GridView.

    Have a look here:

    http://www.west-wind.com/weblog/post...mmandArguments

    Specifically the second technique. This allows you to set the CommandArgument of a control, which allows you to set it to the Primary Key of your data, so that you can reference back to the original data to perform your update.

    Gary

  7. #7

    Thread Starter
    Addicted Member tgf-47's Avatar
    Join Date
    Feb 2010
    Location
    CapeTown, South Africa -34.01244,18.337415
    Posts
    209

    Re: Get cell value of DataGrid???

    Thanks Gary

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width