Data only populated on first page

M

Mark

I have a user control that I am using within a datagrid to display many
instances of this control w/ paging.
I'm using the DataBinder.Eval to set the properties of the control within
the aspx page.
ex. --> Description='<%#DataBinder.Eval(Container.DataItem,
"description")%>'

I have Autogeneratecolumns set to false because I don't want it to display
the data in columns, I just need to set the data to properties of my
control.

Anyway, it works fine when the page loads, but when I change the page, the
data doesn't get populated on the other pages.
If I set the Autogenerate columns = true it works on every page. How do I
get around not showing the columns, but still
get the data?? Please help.

thanks.
 
M

Mark

HELP ME DATAGRID GIRL!!! :)

Yes, I am rebinding the data on that event, the same as I am when I load the
page, except I'm also setting the current page
index also. Here's the code:

public void Grid_Change(Object sender, DataGridPageChangedEventArgs e)
{
DataTable objDT;

// Set CurrentPageIndex to the page the user clicked.

dgMain.CurrentPageIndex = e.NewPageIndex;

// Put user code to initialize the page here

objDT=objExp.GetVerifiedItems();

dgMain.DataSource = objDT;

dgMain.DataBind();

}
 
R

Rajesh Tiwari

bind the data on page load also.it may solve your problem.dont check
IsPostBack etc.

Rajesh
 
M

Mark

I was already doing that, but I tried NOT doing it on load and still the
same result. This has to be a bug. It makes no sense that it would work when
the page initially loads, but then won't work when you change pages.

Just create a simple user control with one label on it, add a property
(Caption) to the user control and put it in a datagrid like below. You'll
see what I mean.

<asp:datagrid id="dgMain" runat="server" Width="95%" Font-Names="Arial"
Font-Size="Smaller" BorderStyle="None"
BorderWidth="2px" GridLines="None" AllowSorting="True" CellSpacing="2"
CellPadding="1" AllowPaging="True"
OnPageIndexChanged="Grid_Change" PageSize="3"
AutoGenerateColumns="false">
<Columns>
<asp:TemplateColumn>
<ItemStyle Width="80px"></ItemStyle>
<ItemTemplate>
<uc1:testcontrol id="Testcontrol1" runat="server" Caption='<%#
DataBinder.Eval(Container.DataItem, "screenname") %>'>
</uc1:testcontrol><br>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle BorderWidth="2px" Font-Size="X-Small" Font-Names="Arial"
BorderColor="#404040" BorderStyle="None"
ForeColor="#0000C0" Position="TopAndBottom" BackColor="Silver"
Mode="NumericPages"></PagerStyle>
</asp:datagrid>
 
R

Rajesh Tiwari

yes i agree with you.i also feel it is a bug.but the problem is that it
is not consistent.i have used datagrid paging almost on 15 modules and
it did not work in one or two.the problem narrowed to the fact that the
EventHandler that is to be called on OnPageIndexChanged is not called
when page index is changed and it leads to all the problems.but i have
still to discover why it happens only in few cases.i am also giving a
sample code which is showing this problem,may be someone may find what
is wrong with this code and clarify our doubts.

<%@ page Language="C#" debug=true %>
<%@ Import namespace="System.Data"%>
<%@ Import namespace="System.Data.SqlClient"%>
<script language="C#" runat=server>
SqlConnection con;
void Page_Load(Object sender,EventArgs e)
{
con=new SqlConnection("Server=rajesh;database=test;uid=sa;pwd=sa");
if(!IsPostBack)
BindGrid();
}
public void DataGrid_Page(Object s,DataGridPageChangedEventArgs p)
{
grd.CurrentPageIndex=p.NewPageIndex;
BindGrid();

}
public void BindGrid()
{
SqlDataAdapter adpt=new SqlDataAdapter("select * from author",con);
DataSet dt=new DataSet();
adpt.Fill(dt,"abcd");
grd.DataSource=dt.Tables["abcd"].DefaultView;
grd.DataBind();
}
</script>
<html>
<body>
<form id=frm1 runat=server>
<asp:datagrid id=grd AllowPaging="True" PageSize="1"
PagerStyle-Mode="NumericPages"
OnPageIndexChanged="DataGrid_Page"
AutoGenerateColumns="true"
runat=server</asp:datagrid>
</form>
</body>
</html>


Rajesh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top