473,468 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

DataGridItem Collection / DataGrid Paging Question

GD
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??

Feb 18 '06 #1
3 2625
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.

"GD" <ge**********@gmail.com> wrote in message
news:11********************@g47g2000cwa.googlegrou ps.com...
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??


Feb 18 '06 #2
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
"GD" wrote:
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??

Feb 19 '06 #3
GD
Exactly, I solved this by iterating through the data source.

Thank you both for the replies

Feb 19 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Paul Perot | last post by:
Hi All: I am populating a Data Table with File/Folder information from my drive... I am then binding this data table to a DataGrid. Due to the size of the DataGrid data, I use the built in...
2
by: Richard Loupatty | last post by:
I put a datagrid in a panel with an overflow set on auto. I want to show just 5 items in the grid. My question is how to make sure that the selecteditem is always visible in the grid. Because...
2
by: Daniel Walzenbach | last post by:
Hi, I have a question regarding the DataGrid control. If paging is enabled the grid binds the data, sets the paging on the top/bottom (or however it is set up) and throws away unnecessary...
3
by: Danky | last post by:
Hello Masters! Anyone can help me with the datagrid, well, the app load a lot of data from DB and it show on the datagrid, and well, I need to allow paging and.... the issue is with the event...
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
1
by: thechaosengine | last post by:
Hi all, Can somebody tell me if the built in paging support for the datagrid works when using a custom collection and a custom business object as the data. I was well pleased when I found that...
3
by: Pat | last post by:
I have a 2 nested Datagrid. When i select a row in the Master Datagrid i populate the Child databrid using myDataGrid.SelectedIndex value as the filter and setting the DataKeyField. I enabled...
0
by: Ken Varn | last post by:
I am sure this has been asked before, but I was wondering is there some way of getting the data values out of a DataGrid Item without having to resort to indexing into the item's cell collection? ...
2
by: Mike Gaab | last post by:
VS 2005 What is the difference between the DataGridItem's ItemIndex and DataSetIndex? Aren't they the same thing? Here is what I found on msdn. ItemIndex Gets the index of the DataGridItem...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.