Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 Accessing Gridview data which is present inside a repeater
Posted by M Rakesh Jain on  2/27/2010 8:39:22 AM Category: C#
Add to my favorites
Email to friend

I have a grid view control which is inside a repeater control. I am able to display the data properly. Now i need to access the data of my grid view. Now on button click i want to save the data present in the grid view to the database. But on button click the data in my repeater collection becomes null. So the data in the grid view too clears. Please help if any one has come across this situation.

Post Your Reply Post New Question

 Viewer's Reply
Access GridView Data Inside a Repeater Control
Answered By Moderator1 on 2/27/2010 10:17:18 PM

Its simple to access a gridview inside repeater. Follow the points below.
1. Repeater control must be bind at the page load or any event that initiates the Repeater Datasource.
2. GridView inside Repeater control must be bind at Repeater OnItemBound event.
2. Follow the sample code, to access the Repeater and its GridView control from a Submit Button, click event.
protected void Button1_Click(object sender, EventArgs e)
foreach (RepeaterItem repeaterItem in Repeater1.Items)
GridView GridView1 = (GridView)repeaterItem.FindControl("GridView1");
foreach (GridViewRow gvr in GridView1.Rows)
Response.Write(GridView1.ClientID + " - " + gvr.Cells[1].Text + "<br/>");
Accessing Gridview data which is present inside a repeater
Answered By M Rakesh Jain on 3/1/2010 2:21:34 AM
Thanks for your reply. I am able to access the rows of the grid view. But the problem
is that my repeater returns three rows. So there are three grid views generated inside my repeater. So i am able to access only the last gridview. Can you please help me on how to access all my gridviews ?
Identify GridView in Repeater Control
Answered By Moderator1 on 3/1/2010 7:29:51 AM
You need to identify which gridview data you are going to access. This can be achieved by placing a CheckBox control for every gridview, then use the GridView data for which checkbox is selected.
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
No Nonsense XML Web Development With PHP - Free 146 Page Preview!
When Good HTML Goes Bad: How You Can Protect Your Web Applications
Introduction to Software Development