Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2006

Tip: Looking for answers? Try searching our database.

DataGridItem Collection / DataGrid Paging Question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
GD - 18 Feb 2006 18:18 GMT
Got a simple ASPX page (.NET v1.1) with a DataGrid displaying a list of
widgets. If the page has a QueryString called WidgetId specific, I need
to automatically mark the specific DataGridItem as selected.

Pretty simple, here's what I did:

for (int i=0; i<dgWidgets.Items.Count; i++)
{
 DataGridItem oDataGridItem = dgWidgets.Items[i];
 if (oDataGridItem.Cells[0].Text == WidgetId)
 {
   dgWidgets.SelectedIndex = i;
   dgWidgets_OnSelectedIndexChanged(this, new EventArgs());
   return;
 }
}

Works like a charm ... However, if the DataGridItem I want to select is
not on the first page of the DataGrid, I run into problems. So, if I
modify the above code slightly to account for DataGrid Paging, here's
what I come up with.

for (int i=0; i<dgWidgets.Items.Count; i++)
{
 DataGridItem oDataGridItem = dgWidgets.Items[i];
 if (oDataGridItem.Cells[0].Text == WidgetId)
 {
   dgWidgets.SelectedIndex = i;
   if (i > dgWidgets.PageSize)
   {
     int iPageIndex =
Convert.ToInt32(Math.Ceiling(i/dgWidgets.PageSize));
     dgWidgets.CurrentPageIndex = iPageIndex;
     dgWidgets_OnPageIndexChanged(this, new
DataGridPageChangedEventArgs(this, iPageIndex));
   }
   dgWidgets_OnSelectedIndexChanged(this, new EventArgs());
   return;
 }
}

However, when stepping through this, I realized that when paging is
enabled, and I'm iterating through the DataGridItems collection, the
collection only contains the Items in the "current page"

Sort of a catch 22 here ... I need to calculate the proper page index
that an Item sits in, but have no access to the complete collection ...

Maybe use the index of the DataTable instead??
Brendan K - 18 Feb 2006 22:31 GMT
I suggest storing the WidgetIDs on page load in an arraylist or collection.
Then when the page reloads because of paging walk the collection or
arraylist and automatically mark the widgets.

ie

foreach(Widgets widgetid in StoredWidgets)
{
//grid code... to mark selected widgets.
}

Hope this helps.

> Got a simple ASPX page (.NET v1.1) with a DataGrid displaying a list of
> widgets. If the page has a QueryString called WidgetId specific, I need
[quoted text clipped - 45 lines]
>
> Maybe use the index of the DataTable instead??
Elton W - 19 Feb 2006 03:36 GMT
HI GD,

When in paging, if you loop thru  Datagrid Items, it only accesses items in
current page. Hence, it’s better to loop thru its data source, and map to
proper pageIndex and item (row) index.

HTH

> Got a simple ASPX page (.NET v1.1) with a DataGrid displaying a list of
> widgets. If the page has a QueryString called WidgetId specific, I need
[quoted text clipped - 45 lines]
>
> Maybe use the index of the DataTable instead??
GD - 19 Feb 2006 16:28 GMT
Exactly, I solved this by iterating through the data source.

Thank you both for the replies

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.