I've created a Dataset programmatically & used it to Databind to a grid view. I have set the page size to 5. There are about 50 rows in the Dataset
When I click a page number at the bottom of the grid, I get an error screen as it has not been st up for data paging.
Is it easy to set up? How would this be done? Is it unusual to do this programmatically? I need the user to choose the server & DB so it must be done on the fly.
When I try to add the rows, I get two sets of rows, so it looks like its still binding to the original rows. Also, the paging still returns an error. It still doesnt work
I am binding it programmatically to a Dataset that is created at runtime
I notice the example is using a design time Datasource. Can this be done with a run time Dataset?
I've created a Dataset programmatically & used it to Databind to a grid view. I have set the page size to 5. There are about 50 rows in the Dataset
When I click a page number at the bottom of the grid, I get an error screen as it has not been st up for data paging.
Is it easy to set up? How would this be done? Is it unusual to do this programmatically? I need the user to choose the server & DB so it must be done on the fly.
I appreciate that, but the trouble is is that I don't know which server this will be querying which means I'd need to have redundant SP's in each DB in each server. (I'm talking around 12 DB's)
Is there a way that paging can be enabled without it being dependant on an SP in the backend?
Can it be done simply by using the runtime Dataset returned?
Thank you, this is the answer! But it's not quite working.
When I click the page number, I get an error in the event handler because the dataset is now null after the post back.
I moved the declaration for the dataset to be a field of the page sapce, & instantiate it in the button which initially binds the dataset to the grid but still the error.
Do I need to save the dataset to session state or something? Here is the code & the error:
DataSet dsTimeToApprove; // field web form scope dataset declaration
Office office =
new Office(dropDownServer.SelectedValue, dropDownOffice.SelectedValue);
DataClass timeToApprove =
new DataClass(office); dsTimeToApprove =
new DataSet();
// grab the dataset
Thank you. I could use session state but would like to take up your idea of using a function.
But wouldn'nt a function also lose its state on postback? I use a function in a class to return a ds which I use to bind the grid, but this loses state.
Could you tell me where I would use this function that would not be affected by a postback
TokyoAnt
Member
22 Points
90 Posts
setting up paging programmatically with a gridview
Apr 10, 2008 01:02 AM|LINK
Hi,
I've created a Dataset programmatically & used it to Databind to a grid view. I have set the page size to 5. There are about 50 rows in the Dataset
When I click a page number at the bottom of the grid, I get an error screen as it has not been st up for data paging.
Is it easy to set up? How would this be done? Is it unusual to do this programmatically? I need the user to choose the server & DB so it must be done on the fly.
Many thanks for any help to get me started here
pnv.ravikira...
Participant
1164 Points
227 Posts
Re: setting up paging programmatically with a gridview
Apr 10, 2008 01:28 AM|LINK
Hi,
In asp.net gridview paging is made easy.. please find below link to know how to set up a gridview for paging.
http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx?path=~/aspnet/samples/data/GridViewPaging.src&file=GridViewPaging_vb.aspx&lang=VB+Source
Happy Coding
</div>Please mark as “Answer” if you find this post helpful
Happy coding..
-------------------------------------------------------------------
Please mark as answer if you find this post helpful.
TokyoAnt
Member
22 Points
90 Posts
Re: setting up paging programmatically with a gridview
Apr 10, 2008 05:22 AM|LINK
Thanks very much for that.
When I try to add the rows, I get two sets of rows, so it looks like its still binding to the original rows. Also, the paging still returns an error. It still doesnt work
I am binding it programmatically to a Dataset that is created at runtime
I notice the example is using a design time Datasource. Can this be done with a run time Dataset?
Many thanks for your help here
Below is the xaml
<asp:GridView ID="gridViewTimeToApprove" runat="server" AllowSorting="True"
style="top: 110px; left: 30px; position: absolute; height: 133px; width: 187px" AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None" PageSize="5"> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#EFF3FB" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> <AlternatingRowStyle BackColor="White" />
<Columns> <asp:BoundField HeaderText ="Resource" DataField ="Resource" SortExpression ="Resource" /> <asp:BoundField HeaderText = "Date" DataField = "Date" SortExpression = "Date" /> <asp:BoundField HeaderText = "Project" DataField = "Project" SortExpression = "Project" /> <asp:BoundField HeaderText = "Activity" DataField = "Activity" SortExpression = "Activity" /> <asp:BoundField HeaderText = "Regular" DataField = "Regular" SortExpression = "Regular" /> <asp:BoundField HeaderText = "Overtime" DataField = "Overtime" SortExpression = "Overtime" /> </Columns>vinz
All-Star
126946 Points
17922 Posts
MVP
Re: setting up paging programmatically with a gridview
Apr 10, 2008 05:25 AM|LINK
Hi TokyoAnt,
Maybe this will give you an idea
http://www.koffeekoder.com/ArticleDetails.aspx?id=210_GridView_Custom_Paging
MessageBox Controls for WebForms | Blog | Twitter | Linkedin
TokyoAnt
Member
22 Points
90 Posts
Re: setting up paging programmatically with a gridview
Apr 10, 2008 05:57 AM|LINK
I appreciate that, but the trouble is is that I don't know which server this will be querying which means I'd need to have redundant SP's in each DB in each server. (I'm talking around 12 DB's)
Is there a way that paging can be enabled without it being dependant on an SP in the backend?
Can it be done simply by using the runtime Dataset returned?
Many thanks
Jigarpatel
Participant
1411 Points
237 Posts
Re: setting up paging programmatically with a gridview
Apr 10, 2008 07:49 AM|LINK
oh yes you can do it.......
you can use that dataset if its content is not change previously after you fill that dataset...
first add event -- its a gridview event
protected void gridview1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gridview1.PageIndex = e.NewPageIndex;
gridview1.datasource = ds.tables["tablename"];
gridview1.databind();
}
thats it and yes set in gridview control allowpaging=true; and pagesize=5
if you get your answer than please mark as answer
Web Developer
India
TokyoAnt
Member
22 Points
90 Posts
Re: setting up paging programmatically with a gridview
Apr 11, 2008 12:48 AM|LINK
Hello Jigarpatel,
Thank you, this is the answer! But it's not quite working.
When I click the page number, I get an error in the event handler because the dataset is now null after the post back.
I moved the declaration for the dataset to be a field of the page sapce, & instantiate it in the button which initially binds the dataset to the grid but still the error.
Do I need to save the dataset to session state or something? Here is the code & the error:
DataSet dsTimeToApprove; // field web form scope dataset declaration
protected void buttonReturnTime_Click(object sender, EventArgs e){
Office office = new Office(dropDownServer.SelectedValue, dropDownOffice.SelectedValue); DataClass timeToApprove = new DataClass(office); dsTimeToApprove = new DataSet(); // grab the datasetdsTimeToApprove = timeToApprove.ReturnTimeAwaitingApproval(listApprover.SelectedValue);
// set the datasource & bind to grid
gridViewTimeToApprove.DataSource = dsTimeToApprove.Tables["TimeToApprove"];gridViewTimeToApprove.DataBind();
}
// the event handler for the Index changing event
protected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e){
gridViewTimeToApprove.PageIndex = e.NewPageIndex;
gridViewTimeToApprove.DataSource = dsTimeToApprove.Tables["TimeToApprove"]; // ERROR HERE !! dsTimeToApprove is nullgridViewTimeToApprove.DataBind();
}
Many thanks Jigarpartel. Almost there
Thanks kindly
Jigarpatel
Participant
1411 Points
237 Posts
Re: setting up paging programmatically with a gridview
Apr 11, 2008 04:46 AM|LINK
oh yes...
bcoz page is refreshing there when you move to next page..
so it return null... so you can save it into session
another solution is that you can make one function which you can call first time to bind dataset ...
and if page index changing than again call that function... but it fill dataset every time when you change grid view page index
so its up to you which method you follow...
i am using second option...
if you get n answer than mark as read......
Web Developer
India
TokyoAnt
Member
22 Points
90 Posts
Re: setting up paging programmatically with a gridview
Apr 11, 2008 06:10 AM|LINK
Hi Jigarpatel,
Thank you. I could use session state but would like to take up your idea of using a function.
But wouldn'nt a function also lose its state on postback? I use a function in a class to return a ds which I use to bind the grid, but this loses state.
Could you tell me where I would use this function that would not be affected by a postback
Many thanks
Jigarpatel
Participant
1411 Points
237 Posts
Re: setting up paging programmatically with a gridview
Apr 11, 2008 07:06 AM|LINK
but i am using function in which it fills datatable every time page index is changing...
but i think you dont want to do that...
so i think first option is bettter for you. if you have 12DB
Web Developer
India