Showing posts with label gridview. Show all posts
Showing posts with label gridview. Show all posts

Wednesday, March 28, 2012

Paged GridView in update panel doesnt work

Hi, I have paged grid view inside an update panel but when I try to change the page in the grid view nothing happens, any ideas why? thanks for your help.

Could you post your code so we can see exactly what you are doing?


Yes, here is the gridviewcode

<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="1" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" PageSize="12" AutoGenerateColumns="False">
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="# Cuota" HeaderText="# Cuota" />
<asp:BoundField DataField="Saldo Inicial" HeaderText="Saldo Inicial" />
<asp:BoundField DataField="MontoInteres" HeaderText="Monto Interes" DataFormatString="{0:C}" HtmlEncode="False" />
<asp:BoundField DataField="Monto Cuota" HeaderText="Monto Cuota" />
<asp:BoundField DataField="MontoCapital" HeaderText="Monto Capital" DataFormatString="{0:C}" HtmlEncode="False" />
</Columns>
</asp:GridView>

The grid view gets filled with data, it just wont let me browse through the grid view pages and it works outside the update panel.


Nevermind, outside the update panel it just postbacks but I hadnt notice the information is the same. I dont have any eventhandler set on the gridview.


I made it work. I just added this code


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

GridView1.DataSource = ViewState["DataTable"] as DataTable ;
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}

Thanks for your help.

Monday, March 26, 2012

PageRequestManager Question

Hello,

I have an update panel which contains a gridview control. When the update panel refreshes or there is a partial postback I would like an indicator that this event has occured in my client side script. I plan to use an if/then statement based on this. I believe this can be done by using an instance of the PageRequestManager class. Could you provide an example of this?

Thanks,

-Robert

It sounds like this tutorial goes over what you're looking for:

http://ajax.asp.net/docs/tutorials/AnimateUpdatePanels.aspx

In your handler for the pageLoaded event, you use the panelsUpdated property to figure out which panels were updated. You can then show whatever indicator you want based on that information.

PageRequestManagerParserErrorException when using a class with asynchronous calls

Hi all,

in the last days i come to a curious problem. On a page i use a GridView to show some data, and on select i show the details in a DetailsView. The Page inherits from a MasterPage and the controls inside an UpdatePanel. The GridView and the DetailsView are populated from different methodes of the same WebService. The WebService is in the same project and a class in App_WebReferences is generated also for testing the WebService function. There are no JavaScriptCalls to the WebService, all is pour C# in codebehind. Now to the problem. When initialice a proxy to the class in the webreference, all works fine and as axpected. But when i generate a class from the wsdl-file with wsdl.exe and use this proxyclass with asynchronous methods inside, the following error pops up:

"Sys.WebForms.PageRequestManagerParserErrorException: The Message received from the Server coul not be parsed. Common couses ..."

The curious is, the first pageload in browser is error free and the firts select also. But when i select a second time a row in the GridView the error pops up, whatever row i select. There is absolute no Response.Write in the hole project and tracing is diabled also.

I use the same struct on several pages in this project and that works. On some pages in this project i use asynchronous calls to WebMethods to populate controls in UpdatePanels without any problems.

Thanks for reading

Problem NOT solved in RC1.


I figured out, the problem comes from my CacheProfile. The WebMethod cache compete with the CacheProfile from the web.config. Simply changed thevaryByParam Attribute and all works like expected.

Saturday, March 24, 2012

Paging a GridView with CSS Friendly Adapters causes a total postback with AJAX Beta1

Hello,

I have upgraded an existing project (Atlas CTP) to the Atlas Beta1 and encountered a problem with a GridView inside an UpdatePanel. I am using theCSS Friendly ASP.NET 2.0 Control Adapters for the GridView and paging the results causes a total postback instead of partial. Here's my code:

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> private System.Collections.Generic.List<string> GetList() { System.Collections.Generic.List<string> list = new System.Collections.Generic.List<string>(); for (int i = 0; i < 100; i++) { list.Add("item " + i.ToString()); } return list; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { ResultsGrid.DataSource = GetList(); ResultsGrid.DataBind(); } } protected void ResultsGrid_PageIndexChanging(object sender, GridViewPageEventArgs e) { ResultsGrid.PageIndex = e.NewPageIndex; ResultsGrid.DataSource = GetList(); ResultsGrid.DataBind(); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head id="Head1" runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:UpdatePanel ID="Updaty" runat="server"> <ContentTemplate> <asp:GridView id="ResultsGrid" runat="server" PageSize="10" AllowPaging="true" OnPageIndexChanging="ResultsGrid_PageIndexChanging" /> </ContentTemplate> </asp:UpdatePanel> </div> </form></body></html>

Using the Atlas CTP the same code caused a partial postback when paging the GridView. Any ideas?

Regards,
Darin

One way around this is to add a trigger to the UpdatePanel for the PageIndexChanging event.

<Triggers>
<asp:AsyncPostBackTrigger ControlID="ResultsGrid" EventName="PageIndexChanging" />
</Triggers>

I tried this and it seem to then update the panel incrementally as expected.


I posted a fix here...http://forums.asp.net/thread/1442598.aspx

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.

Paging and Sorting in GridView April CTP

Hi,

This start happing only after I upgraded to April release, with March release there was no problem.

I'm using updatepanel and gridview and have a ObjectDataSource which get some QueryStringParameter from the Request. When I'm trying to sort the gridview I'm getting a javascript error saying "Value cannot be null. Parameter name: error.

When trying to debug it I found that when sorting, the request URL got changed, and for example if the URL was :http://mySite.com/Default.aspx?kw=123&from=4/18/2006&to=4/19/2006

It got changed to :http://mySite.com/Default.aspx?kw=123&from=4/18/2006&to=4/19/2006Default.aspx?kw=123&from=4/18/2006&to=4/19/2006

Any thoughts?

Thanks

L

Hi,

I found the cause of the problem.

When ever there is a parameter in the URL that has \ like: &to=4\1\2006&..

Atlas April CTP is going crazy... and can't handle that. I have changed my date format to 4_1_2006 etc. and it's working, but still it's kind of a big deal.

Can any one confirm it's a known bug?

Thanks

Lior

Paging gridview inside ATLAS tabcontrol

Hi, I have a dynamicly generated gridview control, inside a dynamically generated tab control. I am having trouble paging the gridview. I get a viewstate corrupted error message at the moment. My page setup is something like this:

Inside the page object, I have an update panel.

Inside the update panel, I have a tab container.

Inside the tab container, I have a number of tabs decided dynamically on page load. There will always be one tab, which doesnt contain a gridview, but there can be other tabs, each containing just a single control, a pageable gridview.

I suspect the fix involves wrapping the gridview in another update panel, which is inside the tab object itself, and triggering the update event for the panel when it needs to page.

Can anyone give me some advice, let me know if I am along the right lines?


Many thanks, Andrew Jones

please take alook at this:

http://forums.asp.net/p/1108841/1703584.aspx

Paging in GridView gets Object Expected Error

I have a grid in an update panel that gets databound at runtime (to index server results). I have implemented paging and it works without atlas. As soon as I place that grid in update panel, paging stops working. All I get is a javascript error saying "line 1 :Object Requiered".

I have tried debugging it but on paging, it doesn't event get to the server.

thanks

Hi Biren,

Have you tried this with the April CTP of Atlas that was released earlier this week?

If it's still a problem, can you please provide some more details on your scenario so that we can investigate?

Thanks,

Eilon


I have done it and it works for me. Object required is a pretty generic error just as the "Object reference not set to an..." in .Net. It could be because of wrong syntax in javascript or html that you might have on the page.

If you don't mind pasting the code on the forum please do so we can look at it.


Just tried it and same error.

here is the code:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Index.aspx.vb" Inherits="Index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Search</title>
<link href="http://links.10026.com/?link=Style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<atlas:ScriptManager EnablePartialRendering="true" ID="atlas1" runat="server" EnableViewState="true" />
<form id="frm1" runat="server">

<atlas:UpdateProgress ID="up11" runat="server" >
<ProgressTemplate >
<table>
<tr>
<th style="color:red">Please wait while your serach results are calculated...</th>
</tr>
<tr>
<td>
<img src="http://pics.10026.com/?src=images/spinner.gif" /></td>
</tr>
</table>

</ProgressTemplate>
</atlas:UpdateProgress>
<atlas:UpdatePanel ID="up1" Mode="conditional" runat="server" >
<ContentTemplate >



<table>
<tr>
<th>A word or phrase in the file: </th><td><asp:TextBox ID="txtsearch" runat="server" /></td>
</tr>
<tr>
<th>All or part of filename: </th><td><asp:TextBox ID="txtfilename" runat="server" /></td>
</tr>
<tr>
<th>When was it modified?:</th>
<td>
<asp:DropDownList ID="lstDuration" runat="server">
<asp:ListItem Text="Don't remember" Value="0" />
<asp:ListItem Text="Within the last week" Value="7" />
<asp:ListItem Text="Past Month" Value="30" />
<asp:ListItem Text="Within the past year" Value="365" />
</asp:DropDownList>
</td>
</tr>
<tr>
<td colspan="2"><asp:Button ID="btnSubmit" runat="server" Text="Search" /></td>
</tr>
</table>

<asp:GridView ID="grdResults" runat="server" CellPadding="4" ForeColor="#333333"
GridLines="None" AllowSorting="True" AllowPaging="True" PageSize="2" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="Document Information">
<ItemTemplate>
<p>
<a href="http://links.10026.com/?link=<%# DataBinder.Eval(Container, "DataItem.path")%>">
<%# DataBinder.Eval(Container, "DataItem.Path")%>
</a>
<br />
<i>Last modified:
<%# DataBinder.Eval(Container, "DataItem.Write")%>
</i>
<br />
</p>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>

</ContentTemplate>

</atlas:UpdatePanel>
</form>
</body>
</html>

Code behind:

Partial Class Index
Inherits System.Web.UI.Page

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click


' Bind DataGrid to the DataSet. DataGrid is the ID for the
' DataGrid control in the HTML section.
Dim source As New DataView(createDS.Tables(0))
grdResults.DataSource = source
grdResults.DataBind()

End Sub
Private Function createDS() As DataSet
Dim cnnOledb As New OleDb.OleDbConnection
Dim strQuery As String

Dim critstr As String = "(contains(filename,'.doc OR .xls OR .ppt OR .asp OR .aspx OR .txt'))"

If txtsearch.Text.Length <> 0 Then
critstr += " AND (contains(contents,'" + condition(txtsearch.Text) + "'))"
End If


strQuery = "Select DocTitle,Filename,VPath,Rank,Characterization,Write,path from SCOPE() where " + critstr + " order by write desc"

Dim connString As String = "Provider=MSIDXS;Data Source='o drive'"

Dim cn As New System.Data.OleDb.OleDbConnection(connString)
Dim cmd As New System.Data.OleDb.OleDbDataAdapter(strQuery, cn)
Dim objDS As New DataSet

cmd.Fill(objDS)

Return objDS
End Function

Function condition(ByVal srchstr As String) As String
Dim arr As String() = srchstr.Split(" ")
For i As Integer = 0 To arr.Length - 1
Dim str1 As String = arr(i)
If str1 <> "AND" And str1 <> "OR" And str1 <> "NOT" Then
arr(i) = "\" + str1 + "\"
End If
Next
Return String.Join(" AND ", arr)
End Function


Sub grdResults_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles grdResults.PageIndexChanging
grdResults.PageIndex = e.NewPageIndex
Dim source As New DataView(createDS.Tables(0))
grdResults.DataSource = source
grdResults.DataBind()

End Sub
End Class


Hi again,

I tried this out and I'm getting the same error. This turns out to be a known bug in the April CTP of Atlas. To work around it, add this code to your Page's Load event handler:

Page.ClientScript.GetPostBackEventReference(this, String.Empty);

Thanks,

Eilon


that works. Thank you. btw ATLAS ROCKS!!

Appears to be an issue in the June CTP too... and if it wasn't for this post, I'd still have the issue.

Thanks guys


Correct, this was not fixed in the June CTP. For now the one line workaround should still be sufficient.

Thanks,

Eilon


In the case of nested UserControls, does this workaround apply? If so, where should the workaround go?

I have a page which contains a UserControl, which in turn contains another UserControl, which contains a GridView wrapped in an UpdatePanel. I tried adding this line to the page's Page_Load and the UserControl's Page_Load, but I get the same generic error:

Line: 10846
Char: 17
Error: Object required
FYI, the offending line appears to be the second one pasted below:

function destroyTree(element, markupContext) {

if (element.nodeType == 1) {


Any ideas?

slp004, can you please give more details as to what you're trying to do? It sounds like other people on this thread have this scenario working so I'm curious what's going on here.

Thanks,
Eilon


I was never able to figure out exactly what the problem was, but by breaking the page up into a number of smaller pages sharing a single master page it started working again. There were just way too many UserControls inside GridView inside FormView inside UserControls inside View areas inside show/hide panels... you get the idea.

I have exactly the same problem - in the same line

 function destroyTree(element, markupContext) {if (element.nodeType == 1) {

My page have three or four levels of nested user controls inside the update panel. The curious thing is the page with the same controls has worked before some change I did - now I am trying to figure it out.


Wow, I figured out the issue.

The error was caused because I have another updatepanel in this page - inside a user control, included in master page. The user control has Visible=false. This scenario causes the error. When I set the user control visibility to true, the error goes off.

The solution is setting the updatepanel (that is inside the user control) mode to Conditional. This solves the problem even if the user control is invisible.

HTH.


I had the same problem and I set all the update panels to conditional and it worked.

Paging Problem in Dynamically added GridView

Hi

I am developing a composite control which includes a GridView. GridView is created and bound in CreateChildControls() method. Normally the control works greate. But if I set AllowPaging=True, it gives an "Object null reference exception". Following is the code. Please give me a solution. [N:B: I have added the PageIndexChages Event also].

protected override void CreateChildControls(){_lsAjaxGridView =new GridView();_lsAjaxGridView.ID ="Leadsoft_AjaxGrid";_lsAjaxGridView.AutoGenerateColumns =this.AutoGenerateColumns;foreach (DataControlField dataControlFieldin Columns) _lsAjaxGridView.Columns.Add(dataControlField);if (this.AllowPaging){if (this.PageSize > 0) _lsAjaxGridView.PageSize =this.PageSize; _lsAjaxGridView.AllowPaging =this.AllowPaging; _lsAjaxGridView.PageIndexChanging +=new GridViewPageEventHandler(Leadsoft_AjaxGrid_PageIndexChanged);}_lsAjaxGridView.DataSource = LSDataSourceView;_lsAjaxGridView.DataBind();}
The exception occurs in "_lsAjaxGridView.DataBind();" only when AllowPaging is True.
Exception Message:"Object reference not set to an instance of an object."

Hi this problem is solved. thing is any DataBinding should be done after the control is added to the form.

lsAjaxGridView.DataSource = LSDataSourceView;

Controls.Add(lsAjaxGridView);
_lsAjaxGridView.DataBind();

Paging Sample

Hi there. Here there is an absolute newbie to Ajax. I'm looking for an Ajax sample for gridview/datagrid paging. Where can i find a -closed- sample?

Thanks in advance.

There is no difference to implement asp:GridView paging?between?asp.net?2.0?and?Ajax.Here?are?some?sample?codes?for?your?reference.
<div>
<asp:UpdatePanel ID="pnlGuestbook" runat="server">
<ContentTemplate>
<asp:GridView ID="gvGuestBook" Width="250" CssClass="NotifyTable" DataSourceID="SqlDataSource2" PageSize="2" AllowPaging="True" runat="server" AutoGenerateColumns="False" DataKeyNames="Message_ID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table>
<tr>
<td><br />
<%#Eval("Subject")%>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ButtonType="Button" >
<ItemStyle VerticalAlign="Top" />
</asp:CommandField>
</Columns>
<PagerSettings Mode="NumericFirstLast" FirstPageText="First" NextPageText="Next" LastPageText="Last" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ProductConnectionString %>"
SelectCommand="SELECT [Message_ID], [From], [Subject], [DateSent] FROM [Message]">
</asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="gvGuestBook" EventName="PageIndexChanged"></asp:AsyncPostBackTrigger>
</Triggers>
</asp:UpdatePanel>
</div>
Wish this can help you.
Thank you. It was so simple. Just drag and drop two controls (ScriptManager and UpdatePanel) and put GridView in UpdatePanel. Love it. =)

Paging(GridView) Inside update Panel

When I enable Paging for a GridView inside a Update Panel for Jan. CTP I get a JavaScript error when I try to page. Is there a work around for this?

Thanks!

Things are working fine with me. I dont know what's the problem in your project.

A.

Wednesday, March 21, 2012

Partial Postbacks and JScript Changes Previously Made on the Client Side

Hello, thank you in advance for taking the time to read this.

I have a Gridview on which I use client-side JScript to add an empty row (hidden) after binding. I place several hidden DIVS in my Gridview template, and then when a user clicks on one of several "expand" buttons in the Gridview, the empty row is made visible and the innerHTML is swapped from the appropriate hidden DIV. This makes the empty row sort of a "Jack of all trades" in that it can display numerous different things as needed by the user.

I am attaching the JScript function below for reference. The empty DIVS are inserted into the client page in the Codebehind using the Gridview's OnRowDataBound handler, but I have no clue how to add a row dynamically server-side, so I went with the client-side script to get the container row done.

Everything works great until you do a sort. The control is AJAX-enabled, so refreshes through a partial postback. Trouble is that the client-side code that adds all the rows does not fire when the grid is refreshed, so none of the "Expand" icons work after the Gridview has been refreshed, because there is no hidden row to make visible and swap content with.

After all this, my question is: How might I:

A) insert an empty row programatically server-side, or

B) fire a client-side script at databinding on a partial postback.

Oh, and I am a pure short-busser when it comes to .NET -- love it but am just now moving up from legacy and feel like a complete idiot. Please speak slowly if you care to answer, and forgive my ignorance.

Javascript adding the rows follows -- I am assigning an ID reference to each row using the "Tracking" field - a unique DB column.

Thanks again for reading, and for any information or hlp you can provide.

Shannon

function fixGrid(idGrid){

var al ="";

var rowcount = 0;for (var t=0;t<idGrid.childNodes[0].childNodes.length-1;t++){

thisName = idGrid.childNodes[0].childNodes[t].nodeName;

if(thisName=="TR"){

rowcount ++;

if(rowcount > 1){

lastCell = idGrid.childNodes[0].childNodes[t].childNodes.length;

thisCell = idGrid.childNodes[0].childNodes[t].childNodes[lastCell-1];

thisTrack = idGrid.childNodes[0].childNodes[t].childNodes[lastCell-2].innerText;

newTR = document.createElement('tr');

newRow1 = newTR.cloneNode(true);

newTD = document.createElement('td');newCol1 = newTD.cloneNode(true);

newCol1.colSpan=9;

newCol1.style.visibility='hidden';

newCol1.style.display='none';

newCol1.id ="td-"+thisTrack;

newCol1.innerHTML="Nothing";

newTR.appendChild(newCol1);

nextRow = idGrid.childNodes[0].childNodes[t].nextSibling;

tableTop = idGrid.childNodes[0].childNodes[t].parentNode;

tableTop.insertBefore(newTR,nextRow);

t++;

}

}else{

alert(thisName);

}

}

returnfalse;

}

Problem solved! I figured I would answer myself for the benefit of future readers.

The call to the client side code in my original post is made fromfixGrid(document.all.gridedit)when the page originally loads.

Obviously, I only want to add the empty container rows once, so I only want this script to be called once each time UpdatePanel1 refreshes, and not if any other panel does. Got it to work that way usingRegisterClientScriptBlock with the update panel ID:

protectedvoid Page_PreRender(object sender,EventArgs e)

{

string script =@."fixGrid(document.all.gridedit);";ScriptManager.RegisterClientScriptBlock(

UpdatePanel1,

typeof(Page),

"ToggleScript",

script,

true);

}

Partial Postback looks like Full Postback

Hello,

my page has some databound controls (gridview, detailsview) and some ajax controls (dropdownextender, modalpopup) and everything works quite normal. On postback, my page renders partially showing a nice updateprogress-box.

But when i place a simple asp:DropDown into the contenttemplate of my updatepanel, everything dissapears on postback, and it seems that the browser is rendering the whole page.

I was not successfull to reproduce this behaviour with a little testpage, and i wont trouble you with posting the whole code. Anyway, i hope anyone can help me to solve this.

Thanks!
Holger

Hello Holger,

I am too facing this problem. Some time my page is full post back and some time not.
But every time it disappers the dropdowm and show it again .

Did you solve the problem.

Thanks,
Deepesh