using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using manage.program;
using manage.aortorsTableAdapters;
using System.Data;
using System.Data.SqlClient;namespace manage
{
public partial class Teacherchange : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{ if (Session["admin"] == null || (string)Session["admin"] == "")
{
Response.Write("您还未登录!");
Response.Redirect("~/Login.aspx");
}
else
{
ListBind(); (Master.FindControl("labUser") as Label).Text = Session["admin"].ToString(); } } } protected void update_Click(object sender, ImageClickEventArgs e)
{
communityTableAdapter update = new communityTableAdapter();
update.UpdateteacherQuery(teahcer.Text, community2.Text);
update.UpdateteacherQuery(DropDownList1.SelectedValue, community1.Text);
Response.Write("更换成功"); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string co = DropDownList1.SelectedValue;
communityTableAdapter update = new communityTableAdapter(); community2.Text = update.GetDataByteacher(co).Rows[0][0].ToString();
} protected void teacherddl_OnItemDataBound(object source, DataListCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Label l = e.Item.FindControl("Label1") as Label;
l.Text = DataBinder.Eval(e.Item.DataItem, "teacher").ToString();
Button b = e.Item.FindControl("loginSuccess") as Button;
b.CommandName = DataBinder.Eval(e.Item.DataItem, "teacher").ToString(); }
} protected void loginSuccess_Click(object sender, EventArgs e)
{
Button b = sender as Button;
teahcer.Text = b.CommandName;
}
private void ListBind()
{
string sql = "SELECT community, teacher FROM community WHERE (psss =1)";//自定义的SQL语句
int recordcount;
DataSet ds = GetPage(sql, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out recordcount);
this.AspNetPager1.RecordCount = recordcount;
//.net的自定义分页
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = ds.Tables[0].DefaultView;
teacherddl.DataSource = pds;
teacherddl.DataBind();
AspNetPager1.CustomInfoHTML = "记录总数:<b>" + AspNetPager1.RecordCount.ToString() + "</b>";
AspNetPager1.CustomInfoHTML += " 总页数:<b>" + AspNetPager1.PageCount.ToString() + "</b>";
AspNetPager1.CustomInfoHTML += " 当前页:<font><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
} protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
ListBind();
} public DataSet GetPage(string sql, int currentPage, int pagesize, out int recordcount)//获取页面数据
{
SqlConnection cn = new SqlConnection("Data Source = CX-PC\\HAPPY;Initial Catalog =Community management;User ID=sa;");
SqlDataAdapter ada = new SqlDataAdapter(sql, cn);
DataSet ds = new DataSet();
int startRow = (currentPage - 1) * pagesize;
ada.Fill(ds, startRow, pagesize, "community");
recordcount = GetPageRecord(sql);
return ds;
} public int GetPagerCount(string sql, int pagesize)
{
int recordcount = GetPageRecord(sql);//方法见上
int pagecount = recordcount / pagesize;
return (recordcount % pagesize == 0 ? pagecount : pagecount + 1);
}
public int GetPageRecord(string sql)
{
SqlConnection cn = new SqlConnection("Data Source = CX-PC\\HAPPY;Initial Catalog =Community management;User ID=sa;"); sql = "select count(*) FROM community WHERE (psss =1)";
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.Connection.Open();
int recordcount = (int)cmd.ExecuteScalar();
return recordcount;
}
}
}
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using manage.program;
using manage.aortorsTableAdapters;
using System.Data;
using System.Data.SqlClient;namespace manage
{
public partial class Teacherchange : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{ if (Session["admin"] == null || (string)Session["admin"] == "")
{
Response.Write("您还未登录!");
Response.Redirect("~/Login.aspx");
}
else
{
ListBind(); (Master.FindControl("labUser") as Label).Text = Session["admin"].ToString(); } } } protected void update_Click(object sender, ImageClickEventArgs e)
{
communityTableAdapter update = new communityTableAdapter();
update.UpdateteacherQuery(teahcer.Text, community2.Text);
update.UpdateteacherQuery(DropDownList1.SelectedValue, community1.Text);
Response.Write("更换成功"); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string co = DropDownList1.SelectedValue;
communityTableAdapter update = new communityTableAdapter(); community2.Text = update.GetDataByteacher(co).Rows[0][0].ToString();
} protected void teacherddl_OnItemDataBound(object source, DataListCommandEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Label l = e.Item.FindControl("Label1") as Label;
l.Text = DataBinder.Eval(e.Item.DataItem, "teacher").ToString();
Button b = e.Item.FindControl("loginSuccess") as Button;
b.CommandName = DataBinder.Eval(e.Item.DataItem, "teacher").ToString(); }
} protected void loginSuccess_Click(object sender, EventArgs e)
{
Button b = sender as Button;
teahcer.Text = b.CommandName;
}
private void ListBind()
{
string sql = "SELECT community, teacher FROM community WHERE (psss =1)";//自定义的SQL语句
int recordcount;
DataSet ds = GetPage(sql, this.AspNetPager1.CurrentPageIndex, this.AspNetPager1.PageSize, out recordcount);
this.AspNetPager1.RecordCount = recordcount;
//.net的自定义分页
PagedDataSource pds = new PagedDataSource();
pds.AllowPaging = true;
pds.PageSize = AspNetPager1.PageSize;
pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
pds.DataSource = ds.Tables[0].DefaultView;
teacherddl.DataSource = pds;
teacherddl.DataBind();
AspNetPager1.CustomInfoHTML = "记录总数:<b>" + AspNetPager1.RecordCount.ToString() + "</b>";
AspNetPager1.CustomInfoHTML += " 总页数:<b>" + AspNetPager1.PageCount.ToString() + "</b>";
AspNetPager1.CustomInfoHTML += " 当前页:<font><b>" + AspNetPager1.CurrentPageIndex.ToString() + "</b></font>";
} protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
ListBind();
} public DataSet GetPage(string sql, int currentPage, int pagesize, out int recordcount)//获取页面数据
{
SqlConnection cn = new SqlConnection("Data Source = CX-PC\\HAPPY;Initial Catalog =Community management;User ID=sa;");
SqlDataAdapter ada = new SqlDataAdapter(sql, cn);
DataSet ds = new DataSet();
int startRow = (currentPage - 1) * pagesize;
ada.Fill(ds, startRow, pagesize, "community");
recordcount = GetPageRecord(sql);
return ds;
} public int GetPagerCount(string sql, int pagesize)
{
int recordcount = GetPageRecord(sql);//方法见上
int pagecount = recordcount / pagesize;
return (recordcount % pagesize == 0 ? pagecount : pagecount + 1);
}
public int GetPageRecord(string sql)
{
SqlConnection cn = new SqlConnection("Data Source = CX-PC\\HAPPY;Initial Catalog =Community management;User ID=sa;"); sql = "select count(*) FROM community WHERE (psss =1)";
SqlCommand cmd = new SqlCommand(sql, cn);
cmd.Connection.Open();
int recordcount = (int)cmd.ExecuteScalar();
return recordcount;
}
}
}
解决方案 »
- sqlhelps.cs 事务怎么用
- 产生10个100以内的随机数
- 索引超出范围。必须为非负值并小于集合大小。
- 急~~~~请问水晶报表中出现错误:该报表不包含表
- repeater事件OnItemCommand="row_itemCommand"不能触发?
- 在电驴下了一个3.5G的vs2005,去不能安装
- 关于梅花树的两个问题
- 如何使用AdRotator控件?
- 在页面中有个按钮,如何在用户点击该按钮时,跳出Nodepad,并打开指定位置的文本文件
- 关于gridview中显示的数据表中的代码字段的问题
- ASP.NET预编译 后还能反编译吗
- 怎么样让下面这个代码的页面显示在一个窗体内时按窗口的高自动换行。。。
{
ListBind();
}
看看你点击第二页的时候从数据库得到了什么
友情提示:既然用了分页控件,sql语句最好也写成分页的 为了提高查询效率数据量越大越明显