DataGrid question

rvermeulen

Member
Joined
Apr 2, 2003
Messages
17
Location
New Jersey
I have a datagrid that is bound to a resultset. I have a checkbox and the column returned from the resultset in the grid.

The problem Im having is this. The result set is returning 50 records, which causes the grid to build beyond the page and you have to scroll the page down to see the entire grid.

What I would like to do is something like the dataList allows you to do. You can set the RepeatColumn attribute and the RepeatDirection to allow the list to build horizontally and look better. Is there a way to accomplish this with the dataGrid ? Or is the solution putting a scroll bar on the datagrid and set its height and width and use the scroll bar within the grid to scroll.

Does anyone have any insight?

Thanks in advance!
Rick
 
You need to use paging on the datagrid. Very easy to do. Bring up the advanced properties window of the datagrid and enable paging from there.
 
paging is correct option.
But if you want a scroll bar
well here is an option

For vertical scrolling within a 600X100 pixel panel:

<asp:panel id="pnlList" Width="600px" Height = "100px" style="overflow:auto" runat="server" >

...Place datagrid or datalist here

</asp:panel>

For Horizontal scrolling:

<asp:panel id="pnlList" Width="600px" Height = "100px" style="overflow:scroll" runat="server" >

...Place datagrid or datalist here

</asp:panel>
[edit]disabled smilies[/edit]
 
Last edited by a moderator:
Ive added paging to the datagrid using a method I found on the internet. Im not sure it is the correct way to do this however. Here is the code I use to load the grid and the corresponding code to allow the paging.

OleDbConnection.Open()
OleDbDataAdapter.Fill(dsSkillSet,"skillset")
Session.Add("ds",dsSkillSet)
DataGrid.DataBind()

Here is the PageIndexChanged event

DataGrid.CurrentPageIndex = e.NewPageIndex
dsSkillSet = Session("ds")
DataGrid.DataBind()

The problem Im having is that if I select records on the first page, and then select the second page, I lose all those records selected on the first page. Should I create another session object to track all the selected items? How do I loop through the items on a specific page, or do I need to loop through the entire grid contents?

Is the session object the proper way to work with this type of paging?

Im still new to this, so please feel free to correct my thinking or ideas.

thanks in advance.
Rick
 
I think the DataGrid.DataBind is clearing what you need ot keep (the details from the 1st page). I dont think you need this in the event.
 
If I dont do a DataGrid.DataBind(), then the paging wont change when you click on each page number to scroll through the list. You need to rebind the grid to get the items to change.

Im wondering if in this event, I need to do some sort of looping and adding selected items to an array or something?

Any ideas?
 
A combination of paging and paneling sounds good.

I think there is a component out there that does it for you. I worked on doing my own solution but then I found it and it works pretty good. you might want to give it a try. http://www.makeitscroll.com
 
Back
Top