473,327 Members | 2,071 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,327 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 1095

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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.