.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Run javascript before sorting or paging the datagrid

Posted By:      Posted Date: October 19, 2010    Points: 0   Category :ASP.Net

Here is what I am trying to do;

I want it so that when the user clicks on the datagrid column headers to sort the records, or when they go to page the datagrid, that a confirmation pop-up appears first, confirming that their changes are going to be lost (unless they click "Cancel").

I have the confirmation pop-up scripted in Javascript and is added to the controls on the page using

onClientClick="return ConfirmDiscardChanges();"

How do I attach this to a datagrid header and to the pager?

Do the columns need to be Template columns and the header text being hyperlink?  If so, how do I set it up so it will, if the user clicks "OK" in the confirmation pop-up,  still sort?


View Complete Post

More Related Resource Links

Sorting and Paging in DataGrid which is inside asp:wizard



Would it be possible to do Sorting and Paging in a DataGrid, My dataGrid is place inside an asp:wizard which is inside an Update Panel.

<asp:UpdatePanel ID="upEditusr" runat="server">
<asp:Wizard ID="Wizard1" runat="server" CssClass="wizUsrAccess" displaycancelbutton="True" 
              oncancelbuttonclick="OnCancelButtonClick" onfinishbuttonclick="OnFinishButtonClick" OnNextButtonClick="OnNextButtonClick" ActiveStepIndex="0" BorderWidth="1px" DisplaySideBar="false">
               <asp:Label ID="SideBarInfo" OnPreRender="InitSideBarLbl" runat="server" /> 
               <asp:DataList ID="SideBarList" OnPreRender="LoadSideBar" RepeatLayout="Flow" Style="display:none;" runat="server"> 
                       <asp:LinkButton ID="SideBarButton" Visible="false" runat="server"></asp:LinkButton> 
                   <SelectedItemStyle Font-Bold="True"  />            

AJAX GridView Paging and Sorting using C# in ASP.Net

To enable the GridView Paging and Sorting to update the GridView Data without refreshing the ASP.Net web page AJAX Extension controls are used. UpdatePanel is used to hold the GridView control that triggers the events for the controls placed inside it. By Default UpdatePanel triggers the asynchronous postbacks for its child controls.

GridView Sorting/Paging : 'REAL' AJAX with Asp.Net Series

This is a continuation of my 'REAL' AJAX with Asp.Net (not Asp.Net AJAX) series posts for those of us trying to stop relying on Asp.Net 'AJAX'.

Ok, nothing too dramatic to start things off, we are going to make some tabled data sortable and pagable all without using a bit of postback. Not only that, but it is going to be incredibly easy!

Manually sorting and paging Gridview without using datasource control

Many a times while working with Gridview we want to work with the paging and sorting functionality without using any datasource control. Gridview is flexible enough to perform these tasks without the use of any datasource control and only a few lines of code.

Optimized Paging and Sorting in ASP.NET GridView

In this article I am going to demonstrate what are the performance drawbacks of using conventional way to page and sort your GridView and then I will demonstrate 'An Optimized way to implement Paging and Sorting'.

Accessing a datagrid element using javascript

Hi all,as I'm not a .Net developer, I'm struggling with some simple problems using the language. I'm trying to insert some javascript functionality, inside my page. What I'm trying to do below...<script language=javascript> function ControlBackupFields(hasBackup) { if (hasBackup.checked = true) { document.aspnetForm.frequencyValue.enabled = true; document.aspnetForm.frequencyUnitList.enabled = true; } else { document.aspnetForm.frequencyValue.enabled = false; document.aspnetForm.frequencyUnitList.enabled = false; } } </script> <asp:datagrid id="dgData" runat="server" AutoGenerateColumns="False" PageSize="20" Width="100%" CssClass="grid" CellPadding="1"> <ItemStyle Height="20px" CssClass="tabletext2" VerticalAlign="Top"></ItemStyle> <HeaderStyle Height="20px" CssClass="tableheading2"></HeaderStyle> <Columns> <asp:TemplateColumn> <ItemTemplate> <asp:TextBox id="volumeID" Runat="server" Visible="false" /> <asp:Label id="volumeName" Runat="server" /> </ItemTemplate> </asp:TemplateColumn> <asp:Templa

DataGrid Paging not working

I got DataGrid Paging functionality on, I can see the paging 1,2,3,4,5.... but when i try to click on it to go to that page the datagrid just goes blank (does not render any record anything). My code is below: <asp:DataGrid ID="dgArticles" AllowPaging="true" Width="100%" AllowSorting="True" AutoGenerateColumns="False" runat="server" OnPageIndexChanged="dgArticles_PageIndexChanged" PageSize="15" EnableViewState= "true"> <ItemStyle Font-Names="Arial" Font-Size="12px" /> <HeaderStyle Font-Bold="true" ForeColor="#FFFFFF" Font-Names="Arial" Font-Size="14px" BackColor="#B2C1D1" /> <PagerStyle Mode="NumericPages" CssClass="FooterButton" Font-Size="Large" /> <AlternatingItemStyle BackColor="#EAEAEA" /> <Columns> <asp:BoundColumn DataField="ContentID" HeaderText="Content ID" /> <asp:HyperLinkColumn DataTextField="Headline" DataNavigateUrlField="ContentID" DataNavigateUrlFormatString=

How to handle sorting and paging when objectdatasource is being built dynamically?

i am building my objectdatasource dynmically when certain buttons are clicked on the page.. and with that the gridview is being displayed with the results of the objectdatasource that was built. So my gridview code looks like this: <asp:GridView ID="GridView1" runat="server" Visible="False" Width="85%"> <EmptyDataTemplate> There are no results for your search. Please try again. </EmptyDataTemplate> </asp:GridView> How can i enable sorting and paging if the datasource is being built on button click event?

Sorting a specific DataGridColumn in wpf DataGrid

Hi! I have a WPF DataGrid that has several DataGridColumns, one of these columns is bound to a Property that is an abstract class. Like this:    public class Cat { public AbstractCatType Type { get; set; } } public class AbstractCatTypeToStringConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { if (value is NiceCatType) { return "Nice"; } if (value is BadCatType) { return "Bad"; } return "unknown"; } public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new System.NotImplementedException(); } } When i click the column header to sort this column I get (not very suprising) an exception System.InvalidOperationException was unhandled Message="Failed to compare two elements in the array." I would like the column to get sorted on the string values it contains (Bad, Nice) but how can I do that? I would prefer to specify a Comparer class for that column or if I could make it forget about the property that it is bound to and sort the strings written in the column. I would prefer not to have to create specific comparers for all of my columns and I have no other SortMemberPath to redirect the sorti

How to execute javascript function from datagrid row

 Hi I need to execute  a javascript function when a row of a datagrid is clicked. I am not sure how to do this. I have tried adding a template column with a button <asp:TemplateColumn>  <ItemTemplate>    <asp:Button ID="myButton" Text="Insert collection" OnClientClick="putData();" runat="server" />  </ItemTemplate></asp:TemplateColumn> And then attaching the javascript to it: myButton.Attributes.Add("onclick", "putData()") But it produces an error. Sorry this is a basic question, but what am I doing wrong?

maintain sorting data during paging

when i sort the grid and it is display in sorted order and when i go to next page it will show data in default order. how to maintain sorting order duing paging

Paging on a different column than the sorting column



Situation: SQL database, Linq to SQL class a ASP.NET page with a LinqDataSource and a gridview.

The table has a ID field, a date field and a Serialnr field.

In my Grid I like to Page on the datefield but to sort on the serialnr field ( or a selectable other field).

Is that possible? Standard the paging is always done on the sort field and when you select a different sort field the page jumps back to the first page., and paging is then done over that sorted column.



Paging and sorting using different columns



Situation: SQL database, Linq to SQL class a ASP.NET page with a LinqDataSource and a gridview.

The table has a ID field, a date field and a Serialnr field.

In my Grid I like to Page on the datefield but to sort on the serialnr field (or a selectable other field.)

Is that possible? Standard the paging is always done on the sort field and when you select a different sort field the page jumps back to the first page, and paging is then done over the sorted column.


Sorting by Calculated Templatefield in Datagrid


I have tried several different approaches .


SOMEONE PLEASE sow me how to sort on template field with a calculated value.

Basically i have half the data i need in the DB and the other half comes from textbox1.text

I take the text in textbox1 and pass it along with a value from the DB (Orig) to a function that returns miles.

                    <asp:Label ID="Label1" runat="server" Text='<%# miles(Eval("Orig"), textbox1.text) %>'>

Whit the above method everything displays correctly but i cannot sort on that column .


I also tried using the miles() function in my select statement for my datasource but that was a nightmare and couldn't get that to work i either got "undeclared function "miles()" or when i fixed that i got "orig" not declared.

Sorry code is so jumbled , entire code is below:

<%@ Page Title="" Language="VB" MasterPageFile="~/Secure/MasterPage.master" %>

<%@ Import Namespace="System.Data.OleDb" %>
<%@ Import Namespace="System.Data" %>
<script runat="server">
    ' I

Datagrid column Sorting generating error


I have a datagrid column whose column values are databinded. I have used DataGridTemplateColumn and i need to use the sorting in this column.

<my:DataGridTemplateColumn SortMemberPath="FileName" Header="Name" IsReadOnly="True" MinWidth="150">

It works and sort the the data but when i edit the data after sorting, i need to re-generate the columns data.

FileListingGrid.ItemsSource = listFiles1;

But this generates "'Sorting' is not allowed during an AddNew or EditItem transaction. "

It works file when column data is not sorted but whenever i sort the data and have to re-generate the column data, it throws the following error.


DataGrid - how to make Column sorting dynamic, to cater for when bound data changes?

I'm using a DataGrid in a VS2010 WPF C# project.  I have bound the DataGrid to an ObservableCollection<SummaryItem>.  When you click on a column heading it sorts the data at that point in time.

Question - How would I arrange such that the sorting in the DataGrid is dynamic, so that when data changes (within the ObservableCollection<SummaryItem>) the sorting keeps working.

Notes: Binding approach is via DataGrid

      private ObservableCollection<SummaryItem> _summaryData = new ObservableCollection<SummaryItem>();
      SummaryDataGrid.ItemsSource = _summaryData;
      SummaryDataGrid.AutoGeneratingColumn += (s, e) =>
        //if (e.Column.Header.ToString() == "ProcessName")
        //  e.Column.Width = new DataGridLength(1, DataGridLengthUnitType.Star);
        e.Column.Width = new DataGridLength(1, DataGridLengthUnitType.Star);
  public class SummaryItem : INotifyPropertyChanged
    public event PropertyChangedEvent

Gridview cancel,sorting,paging


Please can you give me the code for gridview sorting,paging and cancel and please also explain methe code for each line.....otherwise i wont understand the code

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend