I have a gridview bound to a linqDataSource control.
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.
Here's my code ( doesn't work )
protected void btnSelectRig_Click(object sender, EventArgs e)
{
//grdLocations.DataBind();
grdLocations.SelectedIndex = -1;
DataSourceView o = grdLocations.DataSourceObject.GetView("DefaultView");
if (grdLocations.DataSourceObject != null)
{
List<RigLocation> list = grdLocations.DataSource as List<RigLocation>;
int i;
for (i = 0; i < list.Count; i++)
{
if (list[i].RigLocationId == Convert.ToInt32(hidCurrentRigId.Value))
{
break;
}
}
grdLocations.PageIndex = i / grdLocations.PageSize;
grdLocations.SelectedIndex = i % grdLocations.PageSize;
nick5454
Member
587 Points
486 Posts
Finding the row of a DataSource bound to linqDataSource
Apr 09, 2012 12:54 PM|LINK
I have a gridview bound to a linqDataSource control.
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.
Here's my code ( doesn't work )
protected void btnSelectRig_Click(object sender, EventArgs e) { //grdLocations.DataBind(); grdLocations.SelectedIndex = -1; DataSourceView o = grdLocations.DataSourceObject.GetView("DefaultView"); if (grdLocations.DataSourceObject != null) { List<RigLocation> list = grdLocations.DataSource as List<RigLocation>; int i; for (i = 0; i < list.Count; i++) { if (list[i].RigLocationId == Convert.ToInt32(hidCurrentRigId.Value)) { break; } } grdLocations.PageIndex = i / grdLocations.PageSize; grdLocations.SelectedIndex = i % grdLocations.PageSize;nick5454
Member
587 Points
486 Posts
Re: Finding the row of a DataSource bound to linqDataSource
Apr 09, 2012 07:14 PM|LINK
See this link for my answer
http://nickturner.wordpress.com/2012/04/09/finding-the-row-in-a-grid-view-bound-to-a-linqdatasource-control/