0% found this document useful (0 votes)
46 views4 pages

Sorting Is Changed When I Go To Next Page !

The document describes an issue where sorting changes when navigating to the next page of a GridView in ASP.NET, and also when clicking the edit button. It includes code for binding the GridView to a DataSet and handling sorting and paging. A reply suggests changing the "binddata()" method to use a DataView and set the default sort column if no sort column is specified in viewstate.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views4 pages

Sorting Is Changed When I Go To Next Page !

The document describes an issue where sorting changes when navigating to the next page of a GridView in ASP.NET, and also when clicking the edit button. It includes code for binding the GridView to a DataSet and handling sorting and paging. A reply suggests changing the "binddata()" method to use a DataView and set the default sort column if no sort column is specified in viewstate.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

dropDown1.SelectedIndex = dropDown1.Items.IndexOf(dropDown1.Items.FindByText(Value)); OR dropDown1.Items.FindByText(Value).selected =true To set selected index using text DropDownList1.Items.FindByText("anil").

Selected = True; Task:

Sorting is changed when i go to next page !


Replies: 2 | Forum thread posted by: Sahoo.satya1984 | Posted on: 2/18/2008 | Category: ASP.NET Forums | Views: 938 | Status: [Member]

Write New Post |

Search Posts |

Resolved Posts |

Un Answered Posts |

Forums Home | Today's Posts |

I can sort a column on the first page,but when i go to second page through paging sorting changed it's order. Another problem is When i click Edit button,sorting is changed as a result data are also changed for which i can't edit the actual row rather i see a different data on the same row to be updated. Here is my code...

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" OnPageIndexChanging="pagemethod" OnSorting="sortmethod" OnRowEditing="editmethod" AutoGenerateColumns="False" PageSize="4" > <Columns> <asp:CommandField HeaderText="Edit" ShowEditButton="True" ButtonType="Button" /> <asp:TemplateField HeaderText="Name" SortExpression="Name">

<ItemTemplate><%#Eval("Name")%></ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtname" %>'></asp:TextBox> </EditItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> protected { void runat="server" Text='<%# Eval("Name")

Page_Load(object

sender,

EventArgs

e)

if { BindGridView(); } } public { DataSet ds ds=binddata(); GridView1.DataSource GridView1.DataBind(); } public void = = new

(!IsPostBack)

BindGridView() DataSet(); ds;

DataSet

binddata()

{ SqlConnection con = new SqlConnection("Server=.;database=emp;uid=sa;pwd=;"); SqlDataAdapter da = new SqlDataAdapter("select * from job", con); con.Open(); DataSet ds = new DataSet(); da.Fill(ds, "emp"); return ds; }

public

void

sortmethod(object

sender, =

GridViewSortEventArgs

e)

{ ViewState["sortcolumn"]

e.SortExpression; == null) "asc"; == "asc"?"desc":"asc";

if (ViewState["sortorder"] { ViewState["sortorder"] = } ViewState["sortorder"]=ViewState["sortorder"].ToString() DataView dv = dv.Sort = ViewState["sortcolumn"] GridView1.DataSource GridView1.DataBind(); } public void pagemethod(object new + " = "

DataView(binddata().Tables[0]); + ViewState["sortorder"]; dv;

sender, =

GridViewPageEventArgs

e)

{ GridView1.PageIndex GridView1.EditIndex BindGridView();

e.NewPageIndex; -1;

} public void editmethod(object sender, = GridViewEditEventArgs e)

{ GridView1.EditIndex BindGridView(); }

e.NewEditIndex;

Replies

Deysomnath
Posted on: 2/20/2008 1:54:53 AM

Change public { SqlConnection SqlDataAdapter con.Open(); DataSet da.Fill(ds, DataView

the

code

of

"binddata()" DataView

metho

con da = ds

= new

new SqlDataAdapter("select =

dv (ViewState["sortorder"]

if { ViewState["sortorder"] } if { ViewState["sortcolumn"] }

(ViewState["sortcolumn"] = "DefaultColumn"; // use a

dv.Sort return }

ViewState["sortcolumn"]

"

You might also like