473,404 Members | 2,137 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

gridview result blank when sort is done.

I have a data grid that I want to sort and page the results.
but when I click on the title to sort or page it returns a blank page. I am using visual studio 2010 C#
here is my aspx code

Expand|Select|Wrap|Line Numbers
  1.      <asp:GridView ID="GridView1"  runat="server" 
  2.                 AutoGenerateColumns="False" PageSize="20"
  3.                 AllowSorting="True" OnSorting="GridView1_Sorting"
  4.                 AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging"
  5.                 style="margin-left: 0px" width="400px" CellPadding="1
  6.                 " ForeColor="#333333" 
  7.                 GridLines="None">
  8.                 <AlternatingRowStyle BackColor="White" />
  9.                 <Columns>
  10.  
  11.  
  12.                    <asp:hyperlinkfield headertext="ImageID"
  13.                    DataTextField="ImageID"
  14.                    DataNavigateUrlFields="ImageID"
  15.                    NavigateUrl ="C:\"
  16.  
  17.  
  18.                    DataNavigateUrlFormatString="./ImageID.jpg" />
  19.  
  20.  
  21.                     <asp:BoundField DataField="GivenName" HeaderText="GivenName" 
  22.                         SortExpression="GivenName" />
  23.                     <asp:BoundField DataField="Surname" HeaderText="Surname" 
  24.                         SortExpression="Surname" />
  25.                     <asp:BoundField DataField="DeathYear" HeaderText="DeathYear" 
  26.                         SortExpression="DeathYear" />
  27.                     <asp:BoundField DataField="BirthYear" HeaderText="BirthYear" 
  28.                         SortExpression="BirthYear" />
  29.                     <asp:BoundField DataField="FatherGivenNm" HeaderText="FatherGivenNm" 
  30.                         SortExpression="FatherGivenNm" />
  31.                     <asp:BoundField DataField="FatherSurname" HeaderText="FatherSurname" 
  32.                         SortExpression="FatherSurname" />
  33.                     <asp:BoundField DataField="MotherSurname" HeaderText="MotherSurname" 
  34.                         SortExpression="MotherSurname" />
  35.                     <asp:BoundField DataField="MotherGivenNm" HeaderText="MotherGivenNm" 
  36.                         SortExpression="MotherGivenNm" />
  37.                     <asp:BoundField DataField="SpouseGivenNm" HeaderText="SpouseGivenNm" 
  38.                         SortExpression="SpouseGivenNm" />
  39.                     <asp:BoundField DataField="SpouseSurname" HeaderText="SpouseSurname" 
  40.                         SortExpression="SpouseSurname" />
  41.                 </Columns>
  42.                 <EditRowStyle BackColor="#2461BF" />
  43.                 <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
  44.                 <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
  45.                 <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
  46.                 <RowStyle BackColor="#EFF3FB" />
  47.                 <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
  48.                 <SortedAscendingCellStyle BackColor="#F5F7FB" />
  49.                 <SortedAscendingHeaderStyle BackColor="#6D95E1" />
  50.                 <SortedDescendingCellStyle BackColor="#E9EBEF" />
  51.                 <SortedDescendingHeaderStyle BackColor="#4870BE" />
  52.             </asp:GridView>
  53.  
  54.  
  55. my code behind
  56.  
  57.  
  58.  
  59.         public void bindGridView(string sortExp, string sortDir)
  60.  
  61.             {
  62.             if (GridView1.Rows.Count >0 )
  63.                 {
  64.  
  65.                 System.Web.HttpContext context = System.Web.HttpContext.Current;
  66.                 fname = context.Session["fname"].ToString();
  67.                 lname = context.Session["lname"].ToString();
  68.                 birthMonth = context.Session["birthMonth"].ToString();
  69.                 birthDay = context.Session["birthDay"].ToString();
  70.                 birthYear = context.Session["birthYear"].ToString();
  71.                 deathMonth = context.Session["deathMonth"].ToString();
  72.                 deathDay = context.Session["deathDay"].ToString();
  73.                 deathYear = context.Session["deathYear"].ToString();
  74.                 fatherFname = context.Session["fatherFname"].ToString();
  75.                 fatherLname = context.Session["fatherLname"].ToString();
  76.                 motherFname = context.Session["motherFname"].ToString();
  77.                 motherLname = context.Session["motherLname"].ToString();
  78.                 spouseFname = context.Session["spouseFname"].ToString();
  79.                 spouseLname = context.Session["spouseLname"].ToString();
  80.                 ViewState["SortExpression"] = sortExp;
  81.  
  82.                 dataTableResult = archiveAccess.GetDeathInfo(fname, lname, birthYear, deathYear, fatherFname, fatherLname, motherFname, motherFname, spouseFname, spouseLname);
  83.  
  84.                 DataView myDataView = new DataView(dataTableResult);
  85.  
  86.                 if ((GridView1 != null))
  87.                     {
  88.                     myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);
  89.                     }
  90.                     GridView1.DataSource = myDataView;
  91.                     GridView1.AllowSorting = true;
  92.                     GridView1.AllowPaging = true;
  93.                     GridView1.DataBind();                
  94.                 }
  95.             }
  96.  
  97.         protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
  98.             {
  99.  
  100.             bindGridView(e.SortExpression, sortOrder);
  101.  
  102.             }
Mar 19 '13 #1
0 1100

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
1
by: Edward | last post by:
On mine ASP 2.0 page I've two gridviews. The second depends on the selected value of the first one. Everything is working ok. When selecting a row from the first, the second gridview is displaying...
4
by: Marcos Beccar Varela | GamaCom Argentina | last post by:
Hello Everyone. I need to use a gridview, that when I use the Update command one of the colums, instead of showing a textbox where the user can write, I need a combobox (listobx), where there are...
2
by: Narshe | last post by:
I have a gridview with datakeyname="Id" that is using a sqldatasource. When I click delete on the gridview, the datakeys property is empty during the deleting event.
5
by: sara | last post by:
I've looked at all the posts I could and don't see the solution. I am aware that the format to get a BLANK when the number is 0 is: $ #,###.00;($ #,###.00);"" But I can't, for the life of me,...
0
by: Amar | last post by:
Hi, I have a generic list with a some objects of a particular class in it. I have implemented a IComparer for the the class and pass it to the List. The list.sort method works fine when the value...
1
by: Ganesh | last post by:
Hi There, I've a GridView contains hyperlink in each row. If user click that link it will open another detail page with all information. After seeing the details user can go back to search...
1
by: Andy B | last post by:
I have a wizard with multiple steps in it. On the first step, I have a gridView that shows the users current input for that particular step. The GridView is bound to an in memory object. When I...
3
by: stoogots2 | last post by:
Using ajax, .net 2.0, and when I click a column header of my gridview (when it has more than say 1000 rows), the data gets sent back to the client (the file size is roughly the same when I monitor it...
3
by: hbhaskar | last post by:
I used the following command to hyperlink $result_id1 = mysql_query("SELECT * FROM query order by case_id"); for ($i=0; $row1=mysql_fetch_array($result_id1); $i++) { //case_no is a field in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.