-
Jun 7th, 2011, 06:44 AM
#1
Thread Starter
Addicted Member
[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:
protected void grid_ItemCommand(object source, DataGridCommandEventArgs e)
{
// stop editing
GV.EditItemIndex = -1;
switch (e.CommandName)
{
case "Insert":
break;
case "Update":
string a = "";
a = e.Item.Cells[1].Text;
break;
case "Cancel":
EditCommandColumn ecc = (EditCommandColumn)GV.Columns[0];
ecc.UpdateText = "Update";
break;
case "Edit":
// begin editing
GV.EditItemIndex = e.Item.ItemIndex;
break;
}
That code is returning blank strings. Please help me get my cell values.
-
Jun 7th, 2011, 05:47 PM
#2
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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Jun 8th, 2011, 01:09 AM
#3
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
-
Jun 8th, 2011, 01:53 AM
#4
Thread Starter
Addicted Member
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.
-
Jun 8th, 2011, 01:54 AM
#5
Thread Starter
Addicted Member
Re: Get cell value of DataGrid???
Oh I want to add to that, I would prefer to use the GridView.
-
Jun 8th, 2011, 06:30 AM
#6
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
-
Jun 8th, 2011, 07:12 AM
#7
Thread Starter
Addicted Member
Re: Get cell value of DataGrid???
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|