Ajax slider for gridview page

Source: Internet
Author: User

1. Create an ASP. NET web project

2. Add a page and create a data class customer,CodeAs follows:

NamespaceWebui. ajaxslider {Public classCustomer{Public StringName {Set;Get;}Public StringAddress {Set;Get;}Public StringPhone {Set;Get;}Public intAge {Set;Get;}Public boolSex {Set;Get;}}}

2. Add the scriptmanager and updatepanel controls to the page and add the gridview control to updatepanel. The Code is as follows:

<  ASP  :  Scriptmanager  ID  = "Scriptmanager1"  Runat  = "Server"> </  ASP  :  Scriptmanager  > <  ASP  :  Updatepanel  ID  = "Updatepanel1" Runat  = "Server"> <  Contenttemplate  > <  ASP  :  Gridview  ID  = "Mygv"  Runat  = "Server"  Autogeneratecolumns  = "False"  Allowpaging  = "True"  Ondatabound = "Mygv_databound"> <  Columns  > <  ASP  :  Boundfield  Headertext  = "Name"  Datafield  = "Name"/> <  ASP  :  Boundfield  Headertext  = "Address"  Datafield = "Address"/> <  ASP  :  Boundfield  Headertext  = "Sex"  Datafield  = "Sex"/> <  ASP  :  Boundfield  Headertext  = "Phone"  Datafield  = "Phone"/> <  ASP :  Boundfield  Headertext  = "Age"  Datafield  = "Age"/> </  Columns  >  </  ASP  :  Gridview  > </  Contenttemplate  > </  ASP  : Updatepanel  > 

3. Add the gridview Control

 <  Pagertemplate  > <  ASP  :  Textbox  ID  = "Textbox1"  Runat  = "Server"  Text  ="  <% # Mygv. pageindex + 1 %> "  Autopostback  = "True"  Ontextchanged  = "Textbox1_textchanged"> </  ASP  :  Textbox  > <  PC3  :  Sliderextender  ID  = "Textbox1_sliderextender"  Runat  = "Server"  Enabled = "True"  Orientation  = "Horizontal"  Targetcontrolid  = "Textbox1">  PC3  :  Sliderextender  > <  ASP  :  Label  ID  = "Lblpage"  Runat  = "Server"  Text ='  <% # "Page" + (mygv. pageindex + 1) + "of" + mygv. pagecount %>  '/> </  Pagertemplate  > 
 
4. Bind data:
 Protected void Page_load ( Object Sender, Eventargs E ){ If (! Ispostback) {loaddate ();}} Public void Loaddate () {mygv. datasource = List (); mygv. databind ();} Public  List < Customer > List (){ List < Customer > List = New  List < Customer > (); List. Add ( New  Customer {Name = "Caodaiming" , Address ="Sichuan" , Age = 23, sex = True , Phone = "13259460884" }); List. Add ( New  Customer {Name = "Caodaiming" , Address = "Sichuan" , Age = 23, sex = True , Phone = "13259460884" }); List. Add ( New Customer {Name = "Caodaiming" , Address = "Sichuan" , Age = 23, sex = True , Phone = "13259460884" }); Return List ;}
 
5. Add a chanage event to the text. The Code is as follows:
Protected voidTextbox1_textchanged (ObjectSender,EventargsE ){TextboxTxtcurrentpage = senderAsTextbox;GridviewrowRowpager = mygv. bottompagerrow;TextboxSlietext = rowpager. cells [0]. findcontrol ("Textbox1")AsTextbox; Mygv. pageindex =Convert. Toint32 (slietext. Text)-1 ;}

6. Add a bound event to the gridview control. The Code is as follows:

Protected voidMygv_databound (ObjectSender,EventargsE ){GridviewrowRowpager = mygv. bottompagerrow;SliderextenderSlider = rowpager. cells [0]. findcontrol ("Textbox1_sliderextender")AsSliderextender; Slider. Maximum = mygv. pagecount; slider. Minimum = 1; slider. Steps = mygv. pagecount ;}
 
7. The running result is as follows:
 
 
 
 

Finished. Close the job.ProgramThere is another small problem. Let's find out and modify it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.