Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. problem in custom paging..

problem in custom paging..

Scheduled Pinned Locked Moved C#
helpdatabasesysadminquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kamalesh5743
    wrote on last edited by
    #1

    Hi all, i'm having problem in custom paging using web application..there is an error saying "Input string was not in a correct format." Here is my coding.. protected void NavigationLink_Click ( Object sender, CommandEventArgs e ) { switch ( e.CommandName ) { case "First": _currentPageNumber = 1; break; case "Last": _currentPageNumber = Int32.Parse(TotalPages.Text); break; case "Next": _currentPageNumber = Int32.Parse(CurrentPage.Text) + 1; break; case "Prev": _currentPageNumber = Int32.Parse(CurrentPage.Text) - 1; break; } BindData(); } public void BindData() { OdbcConnection myconn; myconn= new OdbcConnection ("DSN=myodbc2;SERVER=localhost;DATABASE=misdb;UID=root;PORT=3306"); OdbcCommand cmd2 = new OdbcCommand("Select * from registration", myconn); cmd2.CommandType=CommandType.StoredProcedure; cmd2.Parameters.Add(new OdbcParameter ("@CurrentPage",OdbcType.Numeric,10)).Value=_currentPageNumber; cmd2.Parameters.Add(new OdbcParameter("@PageSize",OdbcType.Numeric,10)).Value=DataGrid.PageSize; cmd2.Parameters.Add(new OdbcParameter("@TotalRecords",OdbcType.Numeric,10)).Direction =ParameterDirection.Output; try { myconn.Open(); DataGrid.DataSource=cmd2.ExecuteReader(); DataGrid.DataBind(); } finally { myconn.Close(); } CurrentPage.Text=_currentPageNumber.ToString(); Double _totalPages = 1; if ( !Page.IsPostBack ) { Int32 _totalRecords = (Int32) cmd2.Parameters["@TotalRecords"].Value; totalPages = _totalRecords / DataGrid.PageSize; TotalPages.Text =(System.Math.Ceiling(_totalPages)).ToString(); } else { _totalPages = Double.Parse(TotalPages.Text); } if ( _currentPageNumber == 1 ) { PreviousPage.Enabled = false; if ( _totalPages > 1 ) { NextPage.Enabled = true; } else { NextPage.Enabled = false; } } else { PreviousPage.Enabled = true; if ( _currentPageNumber == _totalPages ) { NextPage.Enabled = false; } else { NextPage.Enabled = true; } } }

    %#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG

    G 1 Reply Last reply
    0
    • K kamalesh5743

      Hi all, i'm having problem in custom paging using web application..there is an error saying "Input string was not in a correct format." Here is my coding.. protected void NavigationLink_Click ( Object sender, CommandEventArgs e ) { switch ( e.CommandName ) { case "First": _currentPageNumber = 1; break; case "Last": _currentPageNumber = Int32.Parse(TotalPages.Text); break; case "Next": _currentPageNumber = Int32.Parse(CurrentPage.Text) + 1; break; case "Prev": _currentPageNumber = Int32.Parse(CurrentPage.Text) - 1; break; } BindData(); } public void BindData() { OdbcConnection myconn; myconn= new OdbcConnection ("DSN=myodbc2;SERVER=localhost;DATABASE=misdb;UID=root;PORT=3306"); OdbcCommand cmd2 = new OdbcCommand("Select * from registration", myconn); cmd2.CommandType=CommandType.StoredProcedure; cmd2.Parameters.Add(new OdbcParameter ("@CurrentPage",OdbcType.Numeric,10)).Value=_currentPageNumber; cmd2.Parameters.Add(new OdbcParameter("@PageSize",OdbcType.Numeric,10)).Value=DataGrid.PageSize; cmd2.Parameters.Add(new OdbcParameter("@TotalRecords",OdbcType.Numeric,10)).Direction =ParameterDirection.Output; try { myconn.Open(); DataGrid.DataSource=cmd2.ExecuteReader(); DataGrid.DataBind(); } finally { myconn.Close(); } CurrentPage.Text=_currentPageNumber.ToString(); Double _totalPages = 1; if ( !Page.IsPostBack ) { Int32 _totalRecords = (Int32) cmd2.Parameters["@TotalRecords"].Value; totalPages = _totalRecords / DataGrid.PageSize; TotalPages.Text =(System.Math.Ceiling(_totalPages)).ToString(); } else { _totalPages = Double.Parse(TotalPages.Text); } if ( _currentPageNumber == 1 ) { PreviousPage.Enabled = false; if ( _totalPages > 1 ) { NextPage.Enabled = true; } else { NextPage.Enabled = false; } } else { PreviousPage.Enabled = true; if ( _currentPageNumber == _totalPages ) { NextPage.Enabled = false; } else { NextPage.Enabled = true; } } }

      %#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Entering something in the CurrentPage field would cause that to happen. To avoid that, use the int.TryParse method to parse the value so that you can easily detect any illegal input.

      Despite everything, the person most likely to be fooling you next is yourself.

      K 1 Reply Last reply
      0
      • G Guffa

        Entering something in the CurrentPage field would cause that to happen. To avoid that, use the int.TryParse method to parse the value so that you can easily detect any illegal input.

        Despite everything, the person most likely to be fooling you next is yourself.

        K Offline
        K Offline
        kamalesh5743
        wrote on last edited by
        #3

        hI, I cant c TryParse method in program.Got any other solution for this problem..?

        %#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG

        G 1 Reply Last reply
        0
        • K kamalesh5743

          hI, I cant c TryParse method in program.Got any other solution for this problem..?

          %#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Of course you can't see any TryParse in the program. I said that you should use TryParse in the program.

          Despite everything, the person most likely to be fooling you next is yourself.

          K 1 Reply Last reply
          0
          • G Guffa

            Of course you can't see any TryParse in the program. I said that you should use TryParse in the program.

            Despite everything, the person most likely to be fooling you next is yourself.

            K Offline
            K Offline
            kamalesh5743
            wrote on last edited by
            #5

            ok thank you.

            %#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups