div12.Controls.Add(pp[5]); div12.Controls.Add(TextBox1yy); div12.Controls.Add(Button1yy);
//生成结束.以上生成的控件也要以放在panel中,一样的效果 PagedDataSource pds = new PagedDataSource();
pds.DataSource = mytb.DefaultView; // 把mytab转换为要直接显示的数据视图
pds.AllowPaging = true; pds.PageSize = 3;
int totalp = (mytb.Rows.Count + pds.PageSize - 1) / pds.PageSize; Label1yy.Text = \总页数为:\ + Convert.ToString(totalp); int curpage; //表示当前页
if (Request.QueryString[\] != null)
curpage = Convert.ToInt32(Request.QueryString[\]); else
curpage = 1;
pds.CurrentPageIndex = curpage - 1;
Label2yy.Text = \当前页:\ + curpage.ToString(); if (!pds.IsFirstPage)
prep.NavigateUrl = Request.CurrentExecutionFilePath + \ + Convert.ToString(curpage - 1);
if (!pds.IsLastPage)
nextp.NavigateUrl = Request.CurrentExecutionFilePath + \ + Convert.ToString(curpage + 1); Repeater1.DataSource = pds;
Repeater1.DataBind(); //把视图赋值给repeater1,重新绑定数据 if (curpage != 1)
firtp.NavigateUrl = Request.CurrentExecutionFilePath + \;
if (curpage != totalp)
lastp.NavigateUrl = Request.CurrentExecutionFilePath + \ + Convert.ToString(totalp);
TextBox1yy.Text = curpage.ToString();//让它显示当前页,直观些 }
protected void Button1yy_Click(object sender, EventArgs e) { //注意,动态生成的控件,在运行之前是不存在的,所以无法直接使用TextBox1,而且是
//让计算机自己去找这个控件(这在前面讲过,把控件名字串,转换为控件名)
TextBox ppp = (TextBox)this.div12.FindControl(\); string p = ppp.Text.Trim();
Response.Redirect(Request.CurrentExecutionFilePath + \ + p); }
protected void LinkButtonDel_Click(object sender, EventArgs e) {
string deleteth =
((LinkButton)sender).CommandArgument.ToString();//取出要删除的编号 Session[\编号\] = deleteth;
Response.Write(\是否确定删除')\); string sql = \工资表 where 编号 ='\ + deleteth + \;//从工资表删除选中的工人
string sql1 = \员工表 where 编号 ='\ + deleteth + \;//删除该工人的基本信息
new Class1().noquery(sql1); new Class1().noquery(sql); }
protected void LinkButtonEdit_Click(object sender, EventArgs e) {
string deleteId =
(((LinkButton)sender).CommandArgument.ToString()).ToString(); Session[\编号\] = deleteId.ToString().Trim(); Response.Redirect(\); }
protected void LinkButtonAdd_Click(object sender, EventArgs e) {
string deleteId =
(((LinkButton)sender).CommandArgument.ToString()).ToString(); Session[\编号\] = deleteId.ToString().Trim(); Response.Redirect(\); }
protected void Button1_Click(object sender, EventArgs e) {
string bh = TextBox1.Text.Trim(); string xm = TextBox2.Text.Trim();
string sql = \编号,姓名,性别,出生日期,毕业院校,职称,电话,基本信息备注 from 员工表 where 编号 ='\ + bh + \姓名 ='\ + xm + \;
DataTable mytb = new Class1().getds(sql); Repeater1.DataSource = mytb; Repeater1.DataBind();
}
图3.8 管理员修改员工基本信息界面
主要代码:
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
string th = Session[\编号\].ToString();
string sql = \* from 工资表 where 编号 ='\ + th + \; DataTable tb = new Class1().getds(sql); TextBox1.Text = tb.Rows[0][\编号\].ToString(); TextBox2.Text = tb.Rows[0][\姓名\].ToString(); TextBox3.Text = tb.Rows[0][\实际工资\].ToString(); TextBox4.Text = tb.Rows[0][\基本工资\].ToString(); TextBox5.Text = tb.Rows[0][\加班补助\].ToString(); TextBox6.Text = tb.Rows[0][\考勤扣除\].ToString();