Getting a Gridview selected cell value directly without loop the gridview

Posted by Manu under C# on 4/14/2009 | Views : 29055 | Status : [Member] | Replies : 1
Visual Stoduio 2008, and C# coding ( Web forms )
I have a GridView and a button in a Web based form. May some one please help me with the following.
When using GridView, how do we get the value directly of a selected cell into a variable or use the value of the selected cell to pass it to a a variable without looping through the grid rows and columns.
All i am asking please, is the code which accessed the Gridview cell value without having to loop through the whole gridview rows and columns. I would like to directly access the selected value without to much code. Just one or two lines of code please.


Posted by: Vuyiswamb on: 4/14/2009 [Member] [MVP] [Administrator] NotApplicable

Good Morning Manu

it not a Good idea to get the value without Looping, What if a user did a multiselect on the Grid. You have to loop on the Gridview and get the select value of the Cells, i have an example that i used in a Ultragridweb

foreach (UltraGridCell cell in ultraGridCycles.DisplayLayout.SelectedCells)

if (cell.Value != null && cell.Value.ToString() != "")
cell.Style.ForeColor = System.Drawing.Color.Red;


Session["Cycles"] = array;

Basucally what i did here i have added the select cells values to a Arraylist and and put them in a Session, you can choose to put the in a session and pass them to a parameterised Method that will call your sp in your DAL

Thank you for Posting in DOTNETFUNDA

We are looking forward for your Reply

Vuyiswa Maseko

Thank you for posting at Dotnetfunda

Manu, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response