asp.net repeater Digital Paging code

Source: Internet
Author: User

ASP tutorial. NET Repeater Digital Paging code
public static string Sort {set; get;}
private static string strSQL;
SqlConnection con = new SqlConnection ("Server=localhost;database=moldsystem;uid=sa;pwd=sa");//This is a global variable

Private PagedDataSource PDS ()
{
if (Textbox4.text!= "")
{
string a = Textbox4.text;
strSQL = "SELECT * from Data_mold where customer_name= '" + A + "'";
DataSet ds = new DataSet ();
SqlDataAdapter SDA = new SqlDataAdapter (strSQL, con);
Sda.fill (ds, "name");
PagedDataSource PDS = new PagedDataSource ();
Pds.datasource = ds.tables["name"].defaultview;
pds.allowpaging = true;//Allow paging
Pds.pagesize = 2;//Number of single page display items
Pds.currentpageindex = Convert.ToInt32 (request.querystring["page");
return PDS;
}
Else
{
strSQL = "SELECT * from Data_mold";
DataSet ds = new DataSet ();
SqlDataAdapter SDA = new SqlDataAdapter (strSQL, con);
Sda.fill (ds, "name");
PagedDataSource PDS = new PagedDataSource ();
Pds.datasource = ds.tables["name"].defaultview;
pds.allowpaging = true;//Allow paging
Pds.pagesize = 2;//Number of single page display items
Pds.currentpageindex = Convert.ToInt32 (request.querystring["page");
return PDS;
}
}
protected void Ddlp_selectedindexchanged (object sender, EventArgs e)
Fired when the Drop-down list box in the//foot template is changed
String pg = Convert.ToString ((Convert.ToInt32 ((DropDownList) sender). SelectedValue)-1);//Get list box currently selected
Response.Redirect ("default2.aspx?page=" + PG);//Page turn
}
protected void Page_Load (object sender, EventArgs e)
{
if (!ispostback)
{
Repeater1.datasource = PDS ();
Repeater1.databind ();
}
}
protected void Repeater1_itemcommand (object source, RepeaterCommandEventArgs e)
{

}
protected void Repeater1_itemdatabound (object sender, RepeaterItemEventArgs e)
{
if (E.item.itemtype = = ListItemType.Item | | e.item.itemtype = = listitemtype.alternatingitem)
{
for (int i = 0; i < E.item.controls.count; i++)
{
Control control = E.item.controls[i];
GetControl (Control);
}
}
if (E.item.itemtype = = Listitemtype.footer)
{
DropDownList DDLP = (DropDownList) E.item.findcontrol ("DDLP");

Hyperlink Lpfirst = (hyperlink) E.item.findcontrol ("Hlfir");
Hyperlink Lpprev = (hyperlink) E.item.findcontrol ("hlp");
Hyperlink Lpnext = (hyperlink) E.item.findcontrol ("HLN");
Hyperlink lplast = (hyperlink) E.item.findcontrol ("Hlla");

PDS (). CurrentPageIndex = Ddlp.selectedindex;


int n = Convert.ToInt32 (PDS (). PageCount);//n Number of pages
int i = Convert.ToInt32 (PDS (). CurrentPageIndex);//i is current page

Label LBLPC = (label) E.item.findcontrol ("LBLPC");
Lblpc.text = N.tostring ();
Label LBLP = (label) E.item.findcontrol ("LBLP");
Lblp.text = Convert.ToString (PDS (). CurrentPageIndex + 1);

if (!ispostback)
{
for (int j = 0; J < N; + +)
{
Ddlp.items.add (Convert.ToString (j + 1));
}
}

if (i <= 0)
{
lpfirst.enabled = false;
lpprev.enabled = false;
Lplast.enabled = true;
Lpnext.enabled = true;
}
Else
{
Lpprev.navigateurl = "page=" + (i-1);
}
if (i >= n-1)
{
Lpfirst.enabled = true;
lplast.enabled = false;
lpnext.enabled = false;
Lpprev.enabled = true;
}
Else
{
Lpnext.navigateurl = "page=" + (i + 1);
}

Lpfirst.navigateurl = "page=0";//page Pass parameter page
Lplast.navigateurl = "page=" + (n-1);

Ddlp.selectedindex = Convert.ToInt32 (PDS (). CurrentPageIndex);//update the currently selected page ordinal in the Drop-down list box
}

}
protected void GetControl (Control control)
{
foreach (Control C in Control.Controls)
{

if (C.hascontrols ())
{
GetControl (c);
}
Else
{
if (C.gettype (). ToString () = "System.Web.UI.WebControls.TextBox")
{
TextBox txt = c as textbox;
Txt.attributes.add ("onclick", "Write ('" + Txt.clientid + ");"); /Double-click is ondblclick
Txt.attributes.add ("onblur", "Update ('" + Txt.clientid + ");");
}
}
}
}
protected void Button1_Click (object sender, EventArgs e)
{
Repeater1.datasource = PDS ();
Repeater1.databind ();
}

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.