How to get GridView column values while looping through the columns?

Hi everybody,

I'm trying to figure out how can I get values from DataFields while  looping through the Grid rows.

Here is what I'm trying to do:

GridViewRow row = null; for (int i = 0; i < this.ProfilesGrid.Rows.Count; i++ )


row =


CheckBox chkbtnApproved = row.FindControl("chkApproved") as CheckBox ;

if (chkbtnApproved != null)


if (chkbtnApproved.Checked == true)


int RegID = (int)this.ProfilesGrid.DataKeys[i].Value ;


//PersonName = row.DataItem["FirstName"] + " " + row.DataItem["LastName"];

PersonName = ((TextBox)row.FindControl("FirstName")).Text + " " + ((TextBox)row.FindControl("LastName")).Text;

Util.RunStoredProc("SaveApprovedPerson", new System.Data.SqlClient.SqlParameter("RegistrationID", RegID));

MessageText = "Dear " + PersonName + ", " +

Environment.NewLine + Environment.NewLine + "Your Registration has been approved! " +

Environment.NewLine + Environment.NewLine + "Welcome to Friendship Circle!";

Util.SendMessage(RegID, Membership.GetUser(),

false, MessageText, "Registration Approved", System.Configuration.ConfigurationManager.AppSettings["DevEmail"] );







I could not figure out how to construct PersonName. Would you please help?

Thanks in advance. 




Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
6/23/2008 7:07:46 PM 72751 articles. 3 followers. Follow

3 Replies

Similar Articles

[PageSpeed] 29

 try to specify the cell ur looking in the row


PersonName = ((TextBox)row.FindControl("FirstName")).Text + " " + ((TextBox)row.FindControl("LastName")).Text;




my friends call me MOI
6/23/2008 8:22:15 PM

I was thinking that I would need to resort to Cells collection, but this approach doesn't sound kosher to me. Using Cells approach I have to know which particular column is bound to my FirstName, etc. I would prefer to access data based on the field names, if possible.

Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
6/23/2008 8:30:29 PM

Yes, looks like the only way to access values from the BoundFields is to use this complex syntax and you should know the position in the GridView. So, I used a different approach. I added extra output parameters to my Stored Procedure and return values I need through the parameters :)

Still it would be nice if GridView control would be enhanced in a future with more easier ability to get underlying data. 


Beware of bugs in the above code; I have only proved it correct, not tried it.
(Donald Knuth)
6/24/2008 4:21:31 PM

Similar Artilces:

How do you get a column value from a gridview column
How do you get a column value from a gridview column in 3.5? I tried this but it does not work.Dim myRow As GridViewRowFor Each myRow In GridView1.Rows    Dim strTest As String = DataBinder.Eval(myRow.DataItem, "EmailSubject")Nextif I change the column to a Template field then EmailSubject = myRow.FindControl("EmailSubject") works but I was hoping for a more direct way of getting a column value EmailSubject = myRow.Cells(4).Text also works but is not flexible if I change the column orderThanks Craig Try: Dim strTest As String = CType(...

Getting column value from a gridview control
I have a grid view control and has one datakey and other columns. In my grid view I have an Edit Control and a Delete Control. 1) When I press Edit control, I am getting datakey value as expected. But I am not getting other column name i.e. pdf_filename 2) when I press Delete control, I should get the datakey value. But I am not getting I am using c#  Please help me Hi vmk, Could you be a littlemore elaborate? like how have you bound your grid? 1.Columns autogenerated 2.Using TemplateFields 3.Using BoundFields.Regards,NaveenPlease remember to click Mark as Answer on the pos...

Get Value from Hidden Column in Gridview control
I have managed to get the value from my hidden field by using the SelectedIndexChanged event and the following line of code:string keyValue = GridView1.SelectedDataKey.Value.ToString()I would however prefer to get access to the hidden column value on the GridView1_RowDataBound event, so that I can then evaluate each row against the hidden columns value and decide whether or not to display the edit button in each row. Can I do this a different way? You can use e.Row.DataItem("field name") in the RowDataBound event -  as long as the field is in your SQL statement doesn't m...

Get value of columns when loop through Gridview onsubmit button function
I have a gridview pre-populated with date, to which I added 2 more columns: one is an empty textbox for the user to enter a number and another is a textbox to add/upate Notes. After the user is finished entering data into the textboxes, they are supposed to click on a submit button under the gridview. At this point I want to fill a table, objDT, with the values from the gridview by looping through every row of the gridview. I don't know how to get the values from the columns from my gridview gvOpenOrder. Here's my gridview:<asp:GridView id="gvOpenOrder" BackColor="#FFFFDC" runat="ser...

Get a Clicked Column Index Integer value for a GridView column using the Sorting Event Handler
I am creating a GridView nested within a UpdatePanel and I got the sorting, paging all down to a sciene using the GridView events handlers. Now, I stumbled to a minor problem that I can't seem to figure out how to go about it. When sorting, I would like the heading color of the clicked sorted column to change (using CSS). I can't seem to dynamically pass the value of the clicked column index to the method. I am using the following reference to change the color of the column but I cannot seem to retreive the value of the clicked index in integer value: GridView1.Columns(trying to...

Get Name of DW Identity Column (column.identity property requires looping thru all columns)
I need to locate the identity column for a DW. Only method i see is use of the columnName.Idenity property - which requires you to traverse all the DW columns and then look up the identity property for each until one is yes. Is there a way just to get the identity column directly - or the Primary Key. thanks, Dave As one can see in he syntax, sorry no. I played around with it this week also as I am using DW.Net2.0 with DataSets and a DataSet can not create update commands from a SQL statements where one has 2 tables. But, now, with the help of DW.Net it can do it ...

How to get display column value in dddw column
Using PB 9. Have a DW with a column of dddw style. Once the user selects a value in the dddw column, how can I get the data column value and the display column value? Thanks. On Nov 25, 10:15=A0am, SamRAm wrote: > Using PB 9. > Have a DW with a column of dddw style. > Once the user selects a value in the dddw column, how can I > get the data column value and the display column value? > Thanks. data value; dw_1.object.column[row] dw_1.getitem<XXX>(row, 'column') display string; ls_display =3D dw_1.describe("evaluate('lookupdisplay(column...

Hide Gridview column based on the column value
I have a grid which i bind with values from Database. I have events to edit and update the grid. I am not using SqlDatasource to connect to DB. Rather i am doing the updating of the grid Programmatically. The Grid is populated based on a dropdown selection Gridview has 4 columns, LID(item template column) ,LVal (Item Template and an Edit Item template column), Lookupid (Item Template and an Edit Item template column) and "Edit" link 4 of 10 Dropdown selections have values in Column 3 (lookupid), rest dont. When they dont have values i want to hide that column 3. Of course i can ...

Getting column value from a gridview
Hi All,  I got a gridview with several columns in it.  I created a "Select" commandfield for column1 and datafield for column2 is pointing to ID of the table. When I clicked on column1 I want to get the ID value so I can redirect to another page with that value.  Anyone? Thanks, Steve Hiuse some similar event handler for the grid view   void GridView_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)    {        int selected = e.NewSelectedIndex;      &nbs...

how to get a column value from gridview
 hi all, i have a gridview, it consists of different columns, projectid is one of the column which is also displayed in gridview. i want this projectid from gridview.Based on this i will pass parameter from this page to other page and i will extract data onto another page. how can i achieve this. and also can i generate hyperlink during runtime ? please reply me it's urgent. thanks in advance The easiest would be to bind the hyperlink in your gridview using the projectid in the querystring.  Then it will be available to the page it links to. Rob Millswww.d...

Get gridview column values
I have a gridview listing products and in each row is a text box for the user to enter a quantity and an 'add to cart' button. I have an add to cart function and I need to pass the values from the selected row in the gridview to this function (ProductID, Quantity etc.) so I have an onclick event for the add to cart button but I cannot figure out how to get the values from the specify gridview row in order to pass them to my function. I've tried Gridview1.SelectedRow.Cells(0).Text but this only seems to work with the bound fields and not template fields (such as the quantity textbox on each...

Getting values from a gridview column
Hi All, Here is my problem, I have a gridview that is using an objectdatasource from an SQL DB. I am wanting to check one of the bound coumns in the gridview for a certain value. Here is the code for my gridview: ' Visible="false" /> ' AlternateText='' /> ...

GridView and How to get value of a column
I would like to retrive the value of a cell in my GridView, it is a username, so that I can use it as a string to do something with it. I have a select command button and then a databound column Username. Don't laugh but here is what I have. Me.GridView2.DataSource = Roles.GetRolesForUser(Me.GridView1.SelectedRow.DataItemIndex.ToString) Thank you, Hi ,Jack:You can do this in the selectedIndexChanged event.protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)    {           ...

How to get any column value in GridView
Hi All,              I have a gridview where in 1st row it has Checkbox control and there are four more columns there like  Select All Group Name CUSIP Address Checkbox 1 Vikrant 0001 Mumbai Checkbox 1 Amrita 0002 Bilaspur Checkbox 2 Ramesh 0003 Mumbai  So my requirement is I have a button below the gridview and when click to button it will find for which of the CheckBox is selected and with the selected checkbox it will find the value of Group ...

Web resources about - How to get GridView column values while looping through the columns? -

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012 - Upcoming stories is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 12/9/2015 11:46:50 AM