 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

July 19th, 2007, 11:40 AM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
datagrid does not display next page
I have page which contains dropdownlist items. When user selects a value, I display a datagrid. Works fine. But when I move to the next page on the datagrid, the datagrid does not display. I know for sure there are records in the next page. Can someone tell me what could be wrong?
|
|

July 19th, 2007, 02:43 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Is the datagrid not showing up at all?
Is the display of the datagrid defendant on an event from the dropdownlist?
-Peter
|
|

July 19th, 2007, 03:18 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Once I select values from dropdownlist the firstpage shows up on datagrid. When I move to next page I don't see the datagrid (even though next page has rows).
Do you want me to post the code?
|
|

July 19th, 2007, 03:36 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
Sure, but please post just the relevant code.
|
|

July 19th, 2007, 03:45 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
<asp:datagrid id="DataGrid1" runat="server" AllowCustomPaging="True" PageSize="1" AllowPaging="True"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="EMPID" HeaderText="EMP ID">
<HeaderStyle Font-Underline="True" Font-Names="verdana"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="LNAME" HeaderText="Last Name">
<HeaderStyle Font-Underline="True"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="PHONENO" HeaderText="Phone Number">
<HeaderStyle Font-Underline="True"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="INSDATE" HeaderText="Req. Date">
<HeaderStyle Font-Underline="True"></HeaderStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="APPROVEDDATE" HeaderText="App. Date">
<HeaderStyle Font-Underline="True"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="Checkbox1" Text="Delete" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle Font-Size="8pt" Font-Bold="True" HorizontalAlign="Right" Position="TopAndBottom"></PagerStyle>
</asp:datagrid>
<PagerStyle BackColor="Navy" ForeColor="White" Font-Size="8pt"
Font-Bold="True" HorizontalAlign="Right"
NextPageText="Next >" PrevPageText="< Prev"
Position="TopAndBottom" />
Code behind:
void BindGrid()
{
myConnection = new OracleConnection(ConfigurationSettings.AppSettings["oraClientConnStr"]);
try
{
string classCode = DropDownListCourse.SelectedValue;
string locCode = DropDownListLoc.SelectedValue;
mySelectQuery = "SELECT * from Training.trschedules_view where classcode = " + classCode;
myConnection.Open();
myCommand = new OracleCommand(mySelectQuery, myConnection);
myReader = myCommand.ExecuteReader();
if (myReader.HasRows)
{
DataGrid1.DataSource=myReader;
DataGrid1.DataBind();
}
}
finally
{
myConnection.Close();
}
}
private void Button1_Click(object sender, System.EventArgs e)
{
BindGrid();
}
|
|

July 19th, 2007, 03:56 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
What about the page index changed event? You need to rebind when that happens.
Hmm. You have custom paging turned on. I'm not sure how this will affect this problem.
-Peter
|
|

July 19th, 2007, 03:56 PM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
I am also wondering... with a page size of 1 why bother with a datagrid? Why not a simpler form view? Do you only want to show 1 record at a time?
-Peter
|
|

July 19th, 2007, 04:21 PM
|
|
Authorized User
|
|
Join Date: Oct 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I changed pagesize to 10 it does same thing. Should I remove custom paging?
|
|

July 20th, 2007, 07:48 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
|
|
If you use custom paging you need to provide the right page data and the page count. This is useful if you have a query that handles the paging. A good example of this would be if you have a huge table, lets say 1 million records. The normal behavior of the paging .NET controls is to take all the data from the query and determine the page count based on your page size and show the records for that page. This means that you are transferring 1 million records EVERY TIME you bind the grid. This is very inefficient. So you write a query/sproc that calculates the pages and the returns just the records for that page (say 10). But now you need to convey to the control how many pages there are and pass the current page index to the query.
Initially, start simple, turn custom paging off and let the control handle the paging logic for you while you are getting it working, then take it from there.
-Peter
|
|

July 22nd, 2007, 12:28 AM
|
|
Friend of Wrox
|
|
Join Date: Aug 2006
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
me too can't find the PageIndexChange event!
try this ..
protected void grd_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
try
{
grd.PageIndex = e.NewPageIndex;
grd.DataSource = ds.Tables[0];
grd.DataBind();
}
catch (Exception ex)
{
lblError.Text = ex.Message;
}
}
Nothing is impossible. The impossible only takes longer. "Digital Fortress, Dan Brown"
|
|
 |