Finding the row of a DataSource bound to linqDataSourcehttp://forums.asp.net/t/1790758.aspx/1?Finding+the+row+of+a+DataSource+bound+to+linqDataSourceMon, 09 Apr 2012 19:14:48 -040017907584923030http://forums.asp.net/p/1790758/4923030.aspx/1?Finding+the+row+of+a+DataSource+bound+to+linqDataSourceFinding the row of a DataSource bound to linqDataSource <p>I have a gridview bound to a linqDataSource control.</p> <p>How do I access the actual data? I need to find the row of a selected item, so I can set the PageIndex then the DataKey. The main problem is the DataSourceObject line. I can't find a way to grab the actual data collection.</p> <p>Here's my code ( doesn't work )</p> <pre class="prettyprint">protected void btnSelectRig_Click(object sender, EventArgs e) { //grdLocations.DataBind(); grdLocations.SelectedIndex = -1; DataSourceView o = grdLocations.DataSourceObject.GetView(&quot;DefaultView&quot;); if (grdLocations.DataSourceObject != null) { List&lt;RigLocation&gt; list = grdLocations.DataSource as List&lt;RigLocation&gt;; int i; for (i = 0; i &lt; list.Count; i&#43;&#43;) { if (list[i].RigLocationId == Convert.ToInt32(hidCurrentRigId.Value)) { break; } } grdLocations.PageIndex = i / grdLocations.PageSize; grdLocations.SelectedIndex = i % grdLocations.PageSize;</pre> <p><br> <br> </p> 2012-04-09T12:54:52-04:004923610http://forums.asp.net/p/1790758/4923610.aspx/1?Re+Finding+the+row+of+a+DataSource+bound+to+linqDataSourceRe: Finding the row of a DataSource bound to linqDataSource <p>See this link for my answer</p> <p>http://nickturner.wordpress.com/2012/04/09/finding-the-row-in-a-grid-view-bound-to-a-linqdatasource-control/ </p> 2012-04-09T19:14:48-04:00