📄 repeater.aspx.cs
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.Sql;
using System.Data.SqlClient;
using DBClass;
using System.Xml;
using System.Text;
using System.Drawing;
using System.IO;
using System.Web.SessionState;
public partial class backup_Repeater : System.Web.UI.Page
{
private static string myConnetionString = "server=ck;uid=sa;pwd=sa;database=91;";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
dpbind();
DropDownList1.SelectedValue = Request.QueryString["typeid"];
TextBox1.Text = Request.QueryString["typeid"];
Labelstr.Text = "select * from ZhouQinfo";
string cmdstr = Labelstr.Text ;
RepeaterO(cmdstr);
this.currPage.Text = "1";
}
}
private void RepeaterO(string str)
{
SqlConnection myConnection = new SqlConnection(myConnetionString);
string cmdString = str;//""
SqlDataAdapter da = new SqlDataAdapter(cmdString, myConnection);
//SqlCommand myCommand = new SqlCommand(cmdString, myConnection);
myConnection.Open();
//SqlDataReader myReader = myCommand.ExecuteReader();
//myRepeater.DataSource = myReader;
//myRepeater.DataBind();
//myReader.Close();
DataSet ds = new DataSet();
da.Fill(ds, "ZhouQinfo");
System.Web.UI.WebControls.PagedDataSource pa = new PagedDataSource();
pa.AllowPaging = true;//允许分页
pa.PageSize = 5;//每页显示5条记录
pa.CurrentPageIndex = Convert.ToInt32(this.currPage.Text) - 1;//当前页为
pa.DataSource = ds.Tables["ZhouQinfo"].DefaultView;
this.myRepeater.DataSource = pa;
this.currPage.Text = (pa.CurrentPageIndex + 1).ToString(); //当前页的提示信息
if (pa.CurrentPageIndex < 1)
{
this.btnPre.Enabled = false;//前一页
this.btnNext.Enabled = true;//后一页
}
else if (pa.CurrentPageIndex == pa.PageCount - 1)
{
this.btnNext.Enabled = false;
this.btnPre.Enabled = true;
}
else
{
this.btnNext.Enabled = true;
this.btnPre.Enabled = true;
}
this.countPage.Text = pa.PageCount.ToString();//一共几页
if (pa.PageCount == 1)
{
this.btnNext.Enabled = false;
this.btnPre.Enabled = false;
}
this.myRepeater.DataBind();
myConnection.Close();
}
protected void btnPre_Click(object sender, EventArgs e)//前一页
{
this.currPage.Text = Convert.ToString(Convert.ToInt32(this.currPage.Text) - 1);
RepeaterO(Labelstr.Text );
}
protected void btnNext_Click(object sender, EventArgs e)//下一页
{
this.currPage.Text = Convert.ToString(Convert.ToInt32(this.currPage.Text) + 1);
RepeaterO(Labelstr.Text );
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Labelstr.Text = "select * from ZhouQinfo where ZhouQH=" + DropDownList1.SelectedItem.Value;
string cmdstr = Labelstr.Text;
RepeaterO(cmdstr);
}
private void dpbind()
{
SqlConnection myConn = new SqlConnection(myConnetionString);
string cmdStr = "select ZhouQH,ZhouQLX from ZhouQinfo";
try
{//绑定下拉菜单
DataSet myset = new DataSet();
myConn.Open();
SqlDataAdapter mydatapter = new SqlDataAdapter(cmdStr, myConn);
mydatapter.Fill(myset);
DataTable dt = myset.Tables["table"];
DropDownList1.Items.Clear();
ListItem item = new ListItem("请选择", "-1");//添加一个默认选项
DropDownList1.Items.Add(item);
for (int i = 0; i < dt.Rows.Count; i++)
{
item = new ListItem(dt.Rows[i][1].ToString(), dt.Rows[i][0].ToString());
DropDownList1.Items.Add(item);
}
//和上面面一样结果。
//DropDownList1.DataSource = myset;
//DropDownList1.DataValueField = dt.Columns["ZhouQH"].ToString();
//DropDownList1.DataTextField = dt.Columns["ZhouQLX"].ToString();
//DropDownList1.DataBind();
}
catch (Exception err)
{
Response.Write("<script>alert('读取记录失败')</script>");
}
finally
{
myConn.Close();
}
}
protected void myRepeater_ItemCommand1(object source, RepeaterCommandEventArgs e)
{
Labelxx.Text = e.CommandArgument.ToString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -