62,074
社区成员
发帖
与我相关
我的任务
分享
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind();
}
}
private void Bind()
{
SQLConstructor.BLL.User user = new SQLConstructor.BLL.User();
this.GVTest.DataSource = user.getAllUser();
this.GVTest.DataBind();
GridView1.DataSource = user.getAllUser();
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;//页码取得的方法.再次绑定数据时,GridView根据新页码自动筛选数据.
this.Bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;//编辑行索引的取得方法,通过事件参数.
this.Bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;//取消
this.Bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int UserID = int.Parse(this.GridView1.DataKeys[e.RowIndex].Value.ToString());
Response.Write(UserID.ToString());
//执行删除代码
//pro.deleteproduct(UserID);
this.Bind();
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "<script>alert('删除成功!')</script>", false);
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
string userid = GridView1.DataKeys[e.RowIndex].Value.ToString();//获取主键
GridViewRow myrow = GridView1.Rows[e.RowIndex]; //取得GridView的行
Label lb = (Label)myrow.FindControl("Label1");
Response.Write(lb.Text);
//string id = ((TextBox)myrow.Cells[1].Controls[0]).Text;
/*Cell[0]代表第一列,如果第一列是模板列.则里面的控件可能不至一个.
* Cell[0].Controls[1]代表第二个控件.
*/
//string name =((TextBox)myrow.Cells[1].Controls[0]).Text;//获取选中行单元格数据
//string pwd = ((LiteralControl)myrow.Cells[2].Controls[2]).Text;
//pwd += ((Label)myrow.Cells[2].Controls[1]).Text;
//pwd += "这里的pwd的结束";
//name += "";// myrow.Cells[2].Controls[0].GetType().ToString();
//Response.Write("id" + name + pwd);
////更新代码
//foreach (Control c in myrow.Cells[0].Controls)
//{
// Response.Write(c.GetType().ToString()+"<br/>");
//}
GridView1.EditIndex = -1;
this.Bind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}