Gridview paging and sorting [Resolved]

Posted by Abhisekjani under ASP.NET on 2/11/2012 | Points: 10 | Views : 2137 | Status : [Member] | Replies : 5
hi...
after set the paging and sorting true when i select 2nd or 3rd page so on on gridview ........ in my web page it show that exception cn't handle but first it show the 1st page data....
why dis happens........
plz reply
thanks
abhisek




Responses

Posted by: Sksamantaray on: 2/12/2012 [Member] Silver | Points: 50

Up
0
Down

Resolved
Hi,
Follow this.

aspx

change
onselectedindexchanged="GridView1_SelectedIndexChanged"
to
OnPageIndexChanging="ChangePage"

And then in code behind

protected void PageChange(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
// Refresh the list
string select2 = "select * from item";
adp = new SqlDataAdapter(select2, con);
DataSet ds3 = new DataSet();

adp.Fill(ds3);
GridView1.DataSource = ds3;

GridView1.DataBind();


}

Thanks,
Sanjay

Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/11/2012 [Member] Silver | Points: 25

Up
0
Down
Attach your code here

Thanks,
Sanjay

Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhisekjani on: 2/12/2012 [Member] Starter | Points: 25

Up
0
Down
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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 runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large"
Font-Underline="True" ForeColor="Red" Text="PRODUCT INFORMATION"></asp:Label>

</div>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label2" runat="server" Text="Category"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList1" runat="server"
onselectedindexchanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList>
<br><br />


&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label3" runat="server" Text="Subcategory"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList2" runat="server"
onselectedindexchanged="DropDownList2_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList>
<br><br>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Label ID="Label4" runat="server" Text="Status"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:DropDownList ID="DropDownList3" runat="server"
onselectedindexchanged="DropDownList3_SelectedIndexChanged"
AutoPostBack="True">
</asp:DropDownList>

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

&nbsp;
<br />
<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Search"
style="height: 26px" />
<br />
<asp:GridView ID="GridView1" runat="server"
onselectedindexchanged="GridView1_SelectedIndexChanged" BackColor="White"
BorderColor="#3333FF" AllowPaging="True">

</asp:GridView>
</form>
</body>
</html>
..........................................................................................

protected void Button1_Click(object sender, EventArgs e)
{

string select2 = "select * from item";
adp = new SqlDataAdapter(select2, con);
DataSet ds3 = new DataSet();

adp.Fill(ds3);
GridView1.DataSource = ds3;

GridView1.DataBind();


}


Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Abhisekjani on: 2/12/2012 [Member] Starter | Points: 25

Up
0
Down
Thanks sir........now its work
can you give me some site add that will describe all properties and events of gridview.......



thanks
abhisek

Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksamantaray on: 2/12/2012 [Member] Silver | Points: 25

Up
0
Down
You can have much idea on gridview from here:
http://www.dotnetfunda.com/articles/article1655-22-gridview-tips-and-tricks-by-sheo-narayan.aspx

Thanks,
Sanjay

Abhisekjani, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response