473,387 Members | 1,501 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,387 software developers and data experts.

nothing seems to be wrong

13
hello all;

I am programming a webpage with .NET C# in which I want to display data from database and I am using custom paging
* (page size = 4)
* I am using imageuttons to navigate (next,prv,first,last) in which I make the decrement or increment but next will only take me to page no. 2, and prv takes me to page no 1. no matter where I am at that point
and here is the code for my entire page because I can't figure where the mistake occurs exactly


Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Web;
  7. using System.Web.SessionState;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using System.Web.UI.HtmlControls;
  11. using MySql.Data.MySqlClient;
  12. using MySql.Data.Types;
  13.  
  14. namespace Yacoup
  15. {
  16.     /// <summary>
  17.     /// Summary description for workgroup.
  18.     /// </summary>
  19.     public class workdetails : System.Web.UI.Page
  20.     {
  21.         protected System.Web.UI.WebControls.Label result;
  22.         protected System.Web.UI.WebControls.Label no1txt;
  23.         protected System.Web.UI.WebControls.Label no2txt;
  24.         protected System.Web.UI.WebControls.Label no3txt;
  25.         protected System.Web.UI.WebControls.Label no4txt;
  26.         protected System.Web.UI.WebControls.ImageButton first;
  27.         protected System.Web.UI.WebControls.ImageButton previous;
  28.         protected System.Web.UI.WebControls.ImageButton last;
  29.         protected System.Web.UI.HtmlControls.HtmlTable resultt;
  30.         protected System.Web.UI.HtmlControls.HtmlTableCell TD7;
  31.         protected System.Web.UI.HtmlControls.HtmlTableCell TD6;
  32.         protected System.Web.UI.HtmlControls.HtmlTableCell td00;
  33.         protected System.Web.UI.HtmlControls.HtmlTableCell td10;
  34.         protected System.Web.UI.HtmlControls.HtmlTableCell td20;
  35.         protected System.Web.UI.HtmlControls.HtmlTableCell td30;
  36.         protected System.Web.UI.HtmlControls.HtmlTableCell TD3;
  37.         public int pcount=0;
  38.         public int pagesize=4;
  39.         public int npage=1;
  40.         public int srow,erow,rcount;
  41.         private DataSet ds=new DataSet();
  42.         private MySqlConnection con=new MySqlConnection("Server=localhost;Database=yacoup;Uid=root;Pwd=root;");
  43.         private MySqlDataAdapter da=new MySqlDataAdapter();
  44.         string TableName="employee";
  45.         string actionpg="workdetails.aspx";
  46.         protected System.Web.UI.WebControls.Table Table1;
  47.         protected System.Web.UI.WebControls.HyperLink h1;
  48.         protected System.Web.UI.WebControls.HyperLink h2;
  49.         protected System.Web.UI.WebControls.HyperLink h3;
  50.         protected System.Web.UI.WebControls.HyperLink h4;
  51.         protected System.Web.UI.WebControls.HyperLink h5;
  52.         int xc=0;
  53.         int i;
  54.         protected System.Web.UI.WebControls.ImageButton next;
  55.  
  56.  
  57.  
  58.  
  59.  
  60. private void Page_Load(object sender, System.EventArgs e)
  61.         {
  62.  
  63.  
  64. h1.NavigateUrl="workdetails.aspx?s=1";
  65. h2.NavigateUrl="workdetails.aspx?s=2";
  66. h3.NavigateUrl="workdetails.aspx?s=3";
  67. h4.NavigateUrl="workdetails.aspx?s=4";
  68. h5.NavigateUrl="workdetails.aspx?s=5";
  69.  
  70. i = Convert.ToInt32("0"+Request.QueryString["s"]);
  71.  
  72.  
  73.  
  74. TareefInit(i,npage);    
  75. }
  76.  
  77.  
  78.  
  79. private void TareefInit(int x,int page)
  80. {
  81. #region ProcessInit
  82.  
  83. if(page==0)
  84. page=1;
  85.  
  86.  
  87. if(x==5)
  88. {da=new MySqlDataAdapter("select * from employee order by empid asc ",con);}
  89. else
  90. {da=new MySqlDataAdapter("select * from employee order by expyear desc",con);}
  91. da.Fill(ds,TableName);
  92.  
  93. rcount=Convert.ToInt32(ds.Tables[TableName].Rows.Count);
  94.  
  95. if(rcount%pagesize==0)
  96. {
  97. pcount=rcount/pagesize;
  98.  
  99. }
  100. else
  101. {
  102. pcount=rcount/pagesize;
  103. pcount++;
  104.  
  105.  
  106. }
  107.  
  108.  
  109. #endregion
  110. TareefSERow();
  111. TareefShow();
  112.  
  113.  
  114. }
  115.  
  116. private void TareefSERow()
  117. {
  118. #region startrow and endrow
  119. if(npage==0 || npage==1)
  120. {
  121. srow=0;
  122. erow=pagesize;
  123. if(rcount<4)
  124. erow=rcount;
  125. //Response.Write(rcount+"<-");
  126.  
  127. }
  128. else
  129. {
  130. int mpage = npage;
  131. srow=(mpage-1)*pagesize;
  132. erow=npage*pagesize;
  133. if(erow>rcount)
  134. erow=rcount;
  135. if(srow<0)
  136. srow=0;
  137.     }
  138.     #endregion
  139. }
  140.  
  141.  
  142. private void TareefShow()
  143. {
  144. xc=0;
  145. #region Show Database Result
  146. for(int i=srow;i<erow;i++)
  147. {
  148. xc++;
  149. if(xc==1)
  150. {  
  151. //cell2
  152. no1txt.Text="&nbsp;&nbsp;";
  153. no1txt.Text+="<font color='#336699'>Employee Name: </font>"+ds.Tables[TableName].Rows[i][1];
  154. no1txt.Text+="<font color='#336699'><br>&nbsp;&nbsp;Employee Work: &nbsp;&nbsp;</font>"+ds.Tables[TableName].Rows[i][2];
  155.  
  156. }            
  157. if(xc==2)
  158. {
  159.  
  160. //cell2
  161. no2txt.Text="&nbsp;&nbsp;";
  162. no2txt.Text+="<font color='#336699'>Employee Name: </font>"+ds.Tables[TableName].Rows[i][1];
  163. no2txt.Text+="<font color='#336699'><br>&nbsp;&nbsp;Employee Work: &nbsp;&nbsp;</font>"+ds.Tables[TableName].Rows[i][2];
  164.  
  165. }
  166.  
  167. if(xc==3)
  168. {
  169.  
  170.     //cell2
  171. no3txt.Text="&nbsp;&nbsp;";
  172. no3txt.Text+="<font color='#336699'>Employee Name: </font>"+ds.Tables[TableName].Rows[i][1];
  173. no3txt.Text+="<font color='#336699'><br>&nbsp;&nbsp;Employee Work: &nbsp;&nbsp;</font>"+ds.Tables[TableName].Rows[i][2];
  174.  
  175.  
  176.  }
  177.  
  178.     if(xc==4)
  179.  {
  180.  
  181. //cell2
  182. no4txt.Text="&nbsp;&nbsp;";
  183. no4txt.Text+="<font color='#336699'>Employee Name: </font>"+ds.Tables[TableName].Rows[i][1];
  184. no4txt.Text+="<font color='#336699'><br>&nbsp;&nbsp;Employee Work: &nbsp;&nbsp;</font>"+ds.Tables[TableName].Rows[i][2];
  185.                 }
  186.  
  187.  
  188. result.Text="Page :"+npage+" out "+pcount;
  189.  
  190.             }
  191.  
  192.         #endregion
  193.  
  194.         TareefClear();
  195.         }
  196.  
  197.         private void TareefClear()
  198.         {
  199.         int z=erow-srow;
  200.  
  201.         for(int y=4;y>z;y--)
  202.         {
  203.         #region TareefRemoveControls
  204.         if(y==4)
  205.         {
  206.         td30.Controls.Clear();
  207.         td30.Attributes.Clear();
  208.         }
  209.         if(y==3)
  210.         {
  211.         td20.Controls.Clear();
  212.         td20.Attributes.Clear();
  213.         }
  214.         if(y==2)
  215.         {
  216.         td10.Controls.Clear();
  217.         td10.Attributes.Clear();
  218.         }
  219.         if(y==1)
  220.         {
  221.         td00.Controls.Clear();
  222.         td00.Attributes.Clear();
  223.         }
  224.  
  225.                 #endregion
  226.             }
  227.  
  228.     if(no1txt.Text=="")
  229.             {
  230.         TD3.Controls.Clear();
  231.         result.Text="No Data Found";
  232.             }
  233.         }
  234.  
  235.         #region Web Form Designer generated code
  236.         override protected void OnInit(EventArgs e)
  237.         {
  238.             //
  239. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  240.             //
  241.             InitializeComponent();
  242.             base.OnInit(e);
  243.         }
  244.  
  245.         /// <summary>
  246.         /// Required method for Designer support - do not modify
  247.         /// the contents of this method with the code editor.
  248.         /// </summary>
  249.         private void InitializeComponent()
  250.         {    
  251.     this.Load += new System.EventHandler(this.Page_Load);
  252.         }
  253.         #endregion
  254.  
  255.             public void nxt_prv(object sender, CommandEventArgs x)
  256.         {
  257.  
  258.             if (x.CommandName == "next" && x.CommandArgument.ToString() == "next")
  259.             {
  260.                 if(!(npage>=pcount))
  261.                 {                    
  262.                    npage++;                    
  263.  
  264.  
  265.                     ds.Clear();
  266.  
  267.                    TareefInit(i,npage);
  268.  
  269.  
  270.             }
  271.  
  272.  
  273.             }
  274.             else if(x.CommandName == "prv" && x.CommandArgument.ToString() == "prv")
  275.             {
  276.                 if(!(npage<=1))
  277.                 {
  278.                     npage++;                
  279.                     ds.Clear();
  280.  
  281.                     TareefInit(i,npage);
  282.                 }
  283.             }
  284.             else if(x.CommandName == "first" && x.CommandArgument.ToString() == "first")
  285.             {
  286.                 npage=1;
  287.  
  288.                 ds.Clear();
  289.  
  290.                TareefInit(i,npage);
  291.             }
  292.  
  293.             else if(x.CommandName == "last" && x.CommandArgument.ToString() == "last")
  294.             {
  295.  
  296.                 npage=pcount;    
  297.                 ds.Clear();    
  298.                 TareefInit(i,npage);
  299.             }
  300.  
  301.         }
  302.  
  303.         private void next_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  304.         {
  305.  
  306.         }
  307.  
  308.         private void previous_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  309.         {
  310.  
  311.         }
  312.  
  313.         private void first_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  314.         {
  315.  
  316.         }
  317.  
  318.         private void last_Click(object sender, System.Web.UI.ImageClickEventArgs e)
  319.         {
  320.  
  321.         }
  322.  
  323.  
  324.  
  325.  
  326.  
  327.     }
  328. }
  329.  
  330.  
Jan 30 '07 #1
5 1227
enreil
86
Have you considered using a DataGrid? If you enable paging for your datagrid in the Property Builder, you'll still have paging functionality and avoid lots of debugging headaches.
Jan 30 '07 #2
nmsreddi
366 256MB
hello

You said you want to display data from database .but from your code i dint get where you are displaying your data.

if its grid you can have display it with paging option and if any reports you are using for display then you have properties directly
Feb 1 '07 #3
hime
13
hello all

thank u for replying to my question, as for my data I am showing it in the function TareefShow(), using labels we used this way because we thought it would be the best way to control the way it will appear on the screen.

as for my question that when I click the next button or any other button the value of (npage//the page we r standing in at that point) wont keep the change it will always go back to the initial value which is 1.

now how we solved that problem

we used cache object to save the change in the npage with each click and here is the code with some explanation I hope it is helpful

Expand|Select|Wrap|Line Numbers
  1.  
  2. public void nxt_prv(object sender, CommandEventArgs x)
  3.     {
  4.   if (x.CommandName == "next" && x.CommandArgument.ToString() == "next")
  5. {
  6.  
  7. if(!(npage>=pcount))   //pcount: No. of pages ,npage: the page we r showing now
  8.     {    
  9.                   //npagecache: the cache opject to save the value of npage in 
  10.       if (Cache.Get("npagecache") != null) 
  11.     {
  12.                  //  we retreive the value from the npagecache and asign it to n page 
  13.       npage = Convert.ToInt32( Cache.Get("npagecache"));        
  14.     }
  15.     npage++;
  16.                 /*after the increment to npage we stored the new value in npagecache  to be able to retreive this value as needed in the program */
  17.     Cache.Insert("npagecache",npage);            
  18.     ds.Clear();                   
  19.     TareefInit(i,npage);                    
  20.     }                
  21. }
  22.  
  23. else if(x.CommandName == "prv" && x.CommandArgument.ToString() == "prv")
  24. {
  25.    if (Cache.Get("npagecache") != null)
  26.     {
  27.       npage = Convert.ToInt32( Cache.Get("npagecache"));        
  28.     }
  29.     if(!(npage<=1))
  30.     {
  31.     npage--;
  32.     Cache.Insert("npagecache",npage);
  33.     ds.Clear();                    
  34.     TareefInit(i,npage);
  35.     }
  36.     }
  37. else if(x.CommandName == "first" && x.CommandArgument.ToString()== "first")
  38. {
  39.  if (Cache.Get("npagecache") != null)
  40.  {
  41.   npage = Convert.ToInt32( Cache.Get("npagecache"));        
  42.  }
  43.  npage=1;
  44. Cache.Insert("npagecache",npage);
  45.  ds.Clear();
  46.  TareefInit(i,npage);
  47. }
  48.  
  49. else if(x.CommandName == "last" && x.CommandArgument.ToString() == "last")
  50. {
  51. if (Cache.Get("npagecache") != null)
  52. {
  53. npage = Convert.ToInt32( Cache.Get("npagecache"));        
  54. }
  55. npage=pcount;
  56. Cache.Insert("npagecache",npage);
  57. ds.Clear();    
  58. TareefInit(i,npage);
  59. }
  60.  
  61. }    
  62.  
  63.  
and off cores the in page load we used IsPostBack to empty the page for each post back now for the page load code


Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3. h1.NavigateUrl="workdetails.aspx?s=1";
  4. h2.NavigateUrl="workdetails.aspx?s=2";
  5. h3.NavigateUrl="workdetails.aspx?s=3";
  6. h4.NavigateUrl="workdetails.aspx?s=4";
  7. h5.NavigateUrl="workdetails.aspx?s=5";
  8.  
  9. i = Convert.ToInt32("0"+Request.QueryString["s"]);
  10.  
  11.      TareefInit(i,npage);    
  12.  
  13.     if(!Page.IsPostBack)
  14.     {
  15.                   //When ever the page is redirected the cache opject will be emptied
  16.       Cache.Remove("npagecache");            
  17.      }                
  18. }        
  19.  
and finally if there is any question or comment please send a reply and if there is any other way to solve the npage problem I would be glad to hear and try it.
Feb 1 '07 #4
enreil
86
Did you consider stashing the page number in a session variable? That may result in less overhead.

I still don't quite get why you chose to not use the DataGrid. It is quite customizable and makes things a whole lot easier for you as a developer. Just some advice for future projects - you can take it or leave it.
Feb 1 '07 #5
hime
13
thank u alot, but the reason we are not considering the change to a datagrid is that we have more than one page with the same design and we are trying to keep it this way as for the future we will use the datagrid :)

about the session variable we r gonna try it for the page

thank u again
Feb 4 '07 #6

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

Similar topics

2
by: Sarah | last post by:
I'm having problems getting the FormBuilder package to work. I've spent the last 3hrs reading what little documentation and examples I could find and the idea seems great, if only it'll actually...
7
by: Danny | last post by:
Newbie here Thanks for the help with this command: print "Status: 204 No Content\n\n"; which returns nothing in a perl script. This is great because I just want my perl script to increment a...
1
by: AJ | last post by:
Have I just wasted money on buying VS.NET Beta 2? I can run the start page but as soon as I try to load a solution file, I get an error within the Microsoft Development Environment as the Common...
96
by: BadPony | last post by:
Anyone using Peoplesoft on a Federated UDB (shared nothing)Environment on Open System Platforms? Preferably AIX, but any war stories would be good. TEA EB-C
13
by: Dune | last post by:
How do I compare a boolean with Nothing? I can't say "If boolVar Is Nothing" because a boolean is not a reference type, but "If boolVar = Nothing" always seems to return true, even if the...
10
by: Steve Last | last post by:
Hi all, I’m using IIS6 for our college Intranet and I’m having trouble using Request.Form. Here is my code: <% If Request.QueryString("action") = "show" Then Response.Write "title: " &...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
5
by: andmarti | last post by:
If I build a strict with: import struct print struck.pack ('i', 1) it returns a '\n'. What's wrong with it??? :( --
7
by: andreas | last post by:
Can someone tell me 1) Is there a difference between closing or disposing a reference data type 2) about nothing dim fr as form2 isnothing(fr) gives true
1
by: optimistx | last post by:
I am trying to learn, which type of javascript code is really good according to the experts of this newsgroup. It might be easy to show few lines of code with nothing to blame, but what about...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.