Saturday, March 24, 2012

Paging a GridView in an UpdatePanel

Has anyone been able to implement paging for a GridView inside an UpdatePanel?

I get a JavaScript error everytime I click on the page number: "Object Required".

Enclosing the GridView control inside an UpdatePanel worked fine for me, including the paging.

Have you tried stepping through your code with VisualStudio? This works really good for me when debugging atlas. Also if your gridview is bound to a SqlDataSource you can enable PagingAndSortingCallbacks, and that has the same effect.


hello.

can you show us your code?

<atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"/>

<atlas:UpdatePanelID="EmpOrders"runat="server"Mode="Conditional">

<Triggers><atlas:ControlEventTriggerControlID="Button1"EventName="Click"/></Triggers>

<ContentTemplate>

<asp:ButtonID="Button1"runat="server"Font-Italic="True"OnClick="Button1_Click1"Text="Search"/><br/>

<asp:GridViewID="GridView1"runat="server"CellPadding="4"ForeColor="#333333"GridLines="None"PageSize="15"AllowPaging="True"AutoGenerateColumns="False"OnPageIndexChanging="GridView1_PageIndexChanging"AllowSorting="True">

<Columns>

<asp:BoundFieldDataField="ShipName"HeaderText="Ship Name"SortExpression="ShipName"/>

<asp:BoundFieldDataField="ShipCountry"HeaderText="Country"SortExpression="Country"/>

<asp:BoundFieldDataField="Freight"HeaderText="Freight"SortExpression="Freight"/>

</Columns>

</asp:GridView>

</ContentTemplate>

</atlas:UpdatePanel>

Codebehind:

protectedvoid GridView1_PageIndexChanging(object sender,GridViewPageEventArgs e)

{

GridView1.PageIndex = e.NewPageIndex;

BindGrid();

}


hello.

well, it looks ok to me.

there's one thing i don't understand: you've added a trigger to the panel and configured it against a button which is also placed inside the panel...

i've built a small page that is working ok here (i've built a struct to simulate the info that is passed as source of the grid). see if it works with your current configuration:

public struct Ship
{
private string _shipName;

public string ShipName
{
get { return _shipName; }
set { _shipName = value; }
}
private string _shipCountry;

public string ShipCountry
{
get { return _shipCountry; }
set { _shipCountry = value; }
}
private string _freight;

public string Freight
{
get { return _freight; }
set { _freight = value; }
}

public Ship( string shipName, string shipCountry, string freight )
{
_shipName = shipName;
_shipCountry = shipCountry;
_freight = freight;
}
}

protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!this.IsPostBack )
{
BindGrid();
}
}

void BindGrid()
{
Ship [] shippes = new Ship[]{
new Ship( "1","1","1" ),
new Ship( "2","2","2" ),
new Ship( "3","3","3" )
};

GridView1.DataSource = shippes;
GridView1.DataBind();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.PageIndex = e.NewPageIndex;

BindGrid();

}

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="true"/>
<atlas:UpdatePanel ID="EmpOrders" runat="server" Mode="Conditional">
<Triggers>
<atlas:ControlEventTrigger ControlID="Button1" EventName="Click"/>
</Triggers>
<ContentTemplate>
<asp:Button ID="Button1" runat="server" Font-Italic="True" Text="Search"/><br/>
<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" PageSize="2" AllowPaging="True"
AutoGenerateColumns="False" OnPageIndexChanging="GridView1_PageIndexChanging" AllowSorting="True">
<Columns>
<asp:BoundField DataField="ShipName" HeaderText="Ship Name" SortExpression="ShipName"/>
<asp:BoundField DataField="ShipCountry" HeaderText="Country" SortExpression="Country"/>
<asp:BoundField DataField="Freight" HeaderText="Freight" SortExpression="Freight"/>
</Columns>
</asp:GridView>
</ContentTemplate>
</atlas:UpdatePanel>
<%= DateTime.Now.ToString() %>
</form>
</body>
</html>

Are you doing custom paging? I'm asking because normally, the GridView control takes care of this automatically (as well the binding -- unlike in DataGrid) so that you don't even have to handle the event. This is assuming that your datasource can handle paging (DataSet does I believe).


hello guys, and yes, i think that he is using the asp.net 1.X binding instead of using the new data source controls...

Yes I′m handling the binding as with .NET v1.x


hello again.

Can you run the sample page i've presented in a previous post?

Luis, your example works fine. The only difference between your code and mine is that you use a Struct as your datagrid's datasource and I use a DataSet.

What do you think?


hello.

well, i think that using a dataset shouldn't make any difference. can you build a sample page that uses a dummy dataset to reproduce the problem and post it here?
I have the same problem using an SQLDatasource. Is it possible that it only work with dataset because with dataset you can generate XML. Maybe with SqlDatasource it doesn't generate Xml so Atlas on gridview with SqlDatasource will no work ?
Luis, I′m working on the dummy page. In the meantime, I noticed that having

EnablePartialRendering="true"

won't let me fire the paging, deleting etc. events

Do you have it set to true?


hello.

yes i have. i've introduced < in my previous post and i think that now you should be able to see everything.

No comments:

Post a Comment