1 Attachment(s)
[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.
Attachment 84217
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.
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
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.
Re: Get cell value of DataGrid???
Oh I want to add to that, I would prefer to use the GridView.
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
Re: Get cell value of DataGrid???