CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.faq_frequently_asked_questions Tags:
Item Type: NewsGroup Date Entered: 1/24/2006 6:55:57 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 185 Views: 237 Favorited: 0 Favorite
186 Items, 10 Pages 1 2 3 4 5 6 7 8 9 10 |< << Go >> >|
hockeyboi16
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/27/2006 12:36:43 PM

0

For some reason my GridView_Sorting() method is not firing at all.

I did put the OnSorting="GridView_Sorting" in the markup tag, but when i run it and set the breakpoint at the GridView_Sorting() method, it isn't working.

Any ideas as to what is going on?

Also, i did set the gridview to enable sorting and paging.

Any help is appreciated, thanks

--whit


--whit
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/27/2006 1:10:24 PM

0

hockeyboi16:
For some reason my GridView_Sorting() method is not firing at all.

I did put the OnSorting="GridView_Sorting" in the markup tag, but when i run it and set the breakpoint at the GridView_Sorting() method, it isn't working.

Any ideas as to what is going on?

Also, i did set the gridview to enable sorting and paging.


Do you have EnableSortingAndPagingCallbacks set to true? If so, sorting won't work. You'll need to either remove it or set it to false.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
hockeyboi16
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/27/2006 1:24:26 PM

0

Ah, that did the trick, thank you so much!

--whit


--whit
hockeyboi16
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource6/28/2006 4:38:20 PM

0

Is there any reason why GridView_Sorting() would fire twice? because that is what is happening for me. In effect, my sort is always going to a descending sort, when i want it to work both ways (Ascending and Descending).

--whit

 


--whit
Vinay.D
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/14/2006 12:12:56 PM

0

hi, i tried out sorting as you had explained and it working, but i have a problem, when i click the next page the sorting order is not there. what do you think the problem might be. i am binding the grid at the page index cahnged handler. please help
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/14/2006 3:19:07 PM

0

Vinay.D:
when i click the next page the sorting order is not there


See the last thread on the 2nd page to this post.

Ryan

Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
oswjos
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/28/2006 3:52:22 PM

0

The problem is that for some reason the GridView loses its DataSource at some point.  What I did to solve the problem of the DataSource being null is that since my GridView is populated upon a click, I added the click event at my page.load and like magic, my DataSource was never null again.  You could use the ViewState or populated the GridView every time the page loads.  Hope this helps.
oswjos
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/28/2006 6:57:35 PM

0

This is what I did to get the sorting to work in every single page of the gridview.  The session variables are updating in the sorting event.  Hope this helps.

 

protected

void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

{

DataTable dt = (DataTable)Session["currentDataSource"];

GridView1.PageIndex = e.NewPageIndex;

//sort

DataView dv = new DataView(dt);

dv.Sort = Session[

"currentSortExpression"].ToString() + " " + ConvertSortDirectionToSql((SortDirection)Session["sortingState"]);

GridView1.DataSource = dv;

GridView1.DataBind();

foreach (GridViewRow row in GridView1.Rows)

{

TableCell cell = row.Cells[2];

DateTime time = Convert.ToDateTime(cell.Text);

cell.Text = time.ToLongDateString();

cell.Wrap =

false;

}

}

keivan1984
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource7/30/2006 4:39:08 PM

0

Thanks for your link. Smile
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/9/2006 4:37:24 AM

0

I just tweaked the suggestions of assemblage and updated my code samples, live examples, and blog entry to allow sort state and data to persist between page changes. You can view the links to the updates here.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
san1850
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/17/2006 2:29:05 PM

0

Hi guys iam trying to implement this sorting method in gridview from yesterday but for some reason it is not working.My code cannot get a datatable as iam getting a dataset from other soure which they cant change and iam getting the data from 4 different tables into gridview.I changed the above code like this for the dataset.Guide me if u can where iam going wrong, when i fire sorting event it does nothing but showing me data not found.

DataSet dataset1 = Grieview.DataSource as DataSet;

if (dataset1!= null)

{

DataView dataView = new DataView();

//dataView = dataset1.Tables[""].DefaultView;

//////Unable to figure out wht to write in Tables as i have 4 tables coming to grid

dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

Gridview.DataSource = dataView;

Gridview.DataBind();

}

Gridview.DataBind();

StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/18/2006 1:20:02 AM

0

Don't know what you're doing wrong, but I was able to get it to work by changing all castings to a DataTable to a DataSet.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
aspnet_spnt
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/28/2006 4:53:48 PM

0

i tried using ur method for sorting but when i try to debug its giving me an error as Error 1 The name 'sortDirection' does not exist in the current context what could be the problem???
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/28/2006 5:06:51 PM

0

aspnet_spnt:
i tried using ur method for sorting but when i try to debug its giving me an error as Error 1 The name 'sortDirection' does not exist in the current context what could be the problem???

That would mean you haven't declared sortDirection. Take a look at the examples on my blog and compare them to what you have. All the examples and code have been tested and work, so you should be able to find your issue.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
aspnet_spnt
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/28/2006 6:04:34 PM

0

thanx for ur reply rayan, I tried looking at ur examples but i couldnt find a way out. Iam new to .net and currently working on a project which was coded by a different person. This is what the grid looks like and i would be waiting for ur reply 

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

      <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />

      <RowStyle BackColor="#EBEBEB" />

      <EditRowStyle BackColor="#7C6F57" />

      <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />

      <PagerStyle BackColor="#0A4A13" ForeColor="White" HorizontalAlign="Center" />

      <HeaderStyle BackColor="#0A4A13" Font-Bold="True" ForeColor="White" />

      <AlternatingRowStyle BackColor="White" />

      <Columns>

          <asp:CommandField ShowSelectButton="True" />

          <asp:TemplateField HeaderText="ID">

              <EditItemTemplate>

                  <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>

              </EditItemTemplate>

              <ItemTemplate>

                  <asp:Label ID="Label1" runat="server" Text='<%# Bind("ID") %>'></asp:Label>

              </ItemTemplate>

          </asp:TemplateField>

          <asp:TemplateField HeaderText="UL">

              <EditItemTemplate>

                  <asp:Label ID="Label2" runat="server" Text='<%# Eval("UL") %>'></asp:Label>

              </EditItemTemplate>

              <ItemTemplate>

                  <asp:Label ID="Label2" runat="server" Text='<%# Bind("UL") %>'></asp:Label>

              </ItemTemplate>

          </asp:TemplateField>

          <asp:BoundField DataField="LAST_NAME" HeaderText="Last N" SortExpression = "LAST_NAME" />

          <asp:BoundField DataField="FIRST_NAME" HeaderText="First N"  SortExpression = "FIRST_NAME"/>

          <asp:BoundField DataField="DATE" HeaderText="Date Registered"  SortExpression = "DATE"/>

         

      </Columns>

    </asp:GridView>

 

 

 

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)

    {

        GridViewRow row = GridView1.SelectedRow;

 

        Label lblID = row.FindControl("Label1") as Label;

        Label lblUL = row.FindControl("Label2") as Label;

 

        Session["myID"] = lblID.Text; 

        Session["myUl"] = lblUL.Text;           

 

        string strFullname = Session["userFname"].ToString() + " " + Session["userLname"].ToString();

        DateTime today = DateTime.Now;

        string strDateLastViewed = today.ToString();

        sql mySqlQuery = new sql();

        mySqlQuery.queryDbVoid("UPDATE USED_LOG SET LAST_VIEWED_BY = '" + strFullname + "', DATE_LAST_VIEWED = '" + strDateLastViewed + "' WHERE (" + "UL = '" + lblUL.Text + "') AND " + "(ID = '" + lblID.Text + "')", ref lblResultsError);

 

        Response.Redirect("summary.aspx");

    }//END GridView1_SelectedIndexChanged

 

 

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)

    {

        GridView1.PageIndex = e.NewPageIndex;

        dataBind(Session["myQuery"].ToString());

    }

 

 

JEmlay
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/28/2006 11:49:47 PM

0

StrongTypes:
Don't know what you're doing wrong, but I was able to get it to work by changing all castings to a DataTable to a DataSet.

Ryan1. Thanks to everyone for this solution.  I'm new to ASP.NET and ran into this issue and had nothing but trouble.  Then I saw your C# solution and spent the better half of the day converting it with no luck then saw the VB translation.  Now I'm up and running.

2. However I, as well, had to change

GridView1.DataSource = ds

to

GridView1.DataSource = dt

I tried to change DataTable to DataSet and found that DataSet.Sort is not valid.  Since I only have one table right now I don't see the harm but if I ever add more tables I might be out of luck later on.  While I'm working on this now can we get a re-write of SortDataTable for Datasets?

This is a no-go:

Dim dataSet As New Data.DataSet()

dataSet.Sort = String.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection)

 

Thanks again, you guys helped me out a great deal!

StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 1:52:19 AM

0

aspnet_spnt:
I tried looking at ur examples but i couldnt find a way out.

Your paging code looks good to me at first glance. What issues are you having with it?

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 2:01:13 AM

0

JEmlay:
I tried to change DataTable to DataSet and found that DataSet.Sort is not valid.  Since I only have one table right now I don't see the harm but if I ever add more tables I might be out of luck later on.  While I'm working on this now can we get a re-write of SortDataTable for Datasets?

Since it uses a DataView for sorting, you'd have to tell it which DataTable in the DataSet to use (i..e. dataSet.Tables[0]) if your datasource is a DataSet.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
aspnet_spnt
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 5:15:57 AM

0

When i used ur C# code to enable sorting its giving me an error Error 1 The name 'sortDirection' does not exist in the current context. I even tried some things from the working example in ur blog, but even that didnt work.
StrongTypes
Asp.Net User
Re: HOW TO: Using sorting / paging on GridView w/o a DataSourceControl DataSource8/29/2006 5:31:21 AM

0

aspnet_spnt:
When i used ur C# code to enable sorting its giving me an error Error 1 The name 'sortDirection' does not exist in the current context. I even tried some things from the working example in ur blog, but even that didnt work.

As I already stated above, that means you aren't declaring sortDirection. I'll need to see all the relevant parts of your code to be able to help you furthur.

Ryan


Ryan Olshan
Microsoft MVP, ASP.NET
Blog | Group | Website | Strong Coders Community

How to ask a question
186 Items, 10 Pages 1 2 3 4 5 6 7 8 9 10 |< << Go >> >|


Free Download:


Web:
Sorting & Paging In GridView ? - ASP.NET Forums If you are using DataSet then this may help you. http://ryanolshan.com/articles/ c-gridview-sorting-paging-w-o-a-datasourcecontrol-datasource ...
Trying to use the FAQ " Sorting and paging in the GridView control ... http://ryanolshan.com/articles/c-gridview-sorting-paging-w-o-a-datasourcecontrol -datasource/. Regards,Vinz "Code, Beer and Music" that's my ...
[web refference]C# GridView Sorting/Paging w/o a DataSourceControl ... 2008年6月19日 ... /c-gridview-sorting-paging-woa-datasourcecontrol-datasource/C# ... on a GridView control without using a DataSourceControl DataSource ...
gridview sorting - Dot Net Search Engine swicki - powered by eurekster C# GridView Sorting/Paging w/o a DataSourceControl DataSource . ... ryanolshan. com/articles/c-gridview-sorting-paging-w-o-a-data. ... How to use sorting in GridView in ASP.Net. Add image in grid header to indicate sort direction. ...
gridview paging issue - ASP.NET Forums hi , iam using a gridview with paging ,but paging doesnot works ,it shows ... /c -gridview-sorting-paging-w-o-a-datasourcecontrol-datasource/ ...

HOW TO: Using sorting / paging on GridView w/o a DataSourceControl ... NET Forums If you are using DataSet then this may help you. http://ryanolshan. com/articles/ c-gridview-sorting-paging-w-o-a-datasourcecontrol-datasource . ...






managing admin / user accounts for your web applications

how to do a language switch in a master page.

problem in casting of this.controls[0] to table

how do we access folders/files in a different web application?

asp.net dropdownlist - "cannot have multiple items selected in a dropdownlist."

any idea how does the preview of "write a new post" work?

how to find whether the url is http://website.com or http://www.website.com

annoyance with framework 1.1 service pack

what is the difference between == and .equals

whidbey: the new compilation model

sql server express dts how to install

what is the difference between # & $ in binding method?

how to develope accounting software

now how to read a message

databindings in asp.net and use/advantage of update panel (with ajax extension)

an idea for caching. is it plausible?

deleting the master table withour deleting the child tables

process must exit before requested information can be determined. error

hide source code while deploying

whidbey: tired with sessions? - use the new profile property to store user information

ms sql mdf database file attached vs created on sql server

how to: make "export to excel" always open excel in a separate window

parser error message

solution to the findcontrol problem

transactions in asp.net

"unable to automatically step into the server. the remote procedure could not be debugged" error

how to navigate an event located in amaster page

requirements for sending mail

problem in gridview datakeynames

how to disable browser back button in asp.net2.0

 
Search This Site:

 
  Privacy | Contact Us
All Times Are GMT