1. 模板頁(yè)中的多選按鈕操作
以下代碼
數(shù)據(jù)庫(kù)中字段為int
1:代表 true
0:代表false
在GridView中把它顯示出來(lái)
(注:此處的ToolTip只是為了在后臺(tái)能得到當(dāng)前數(shù)據(jù)的ID,在選中之后直接進(jìn)行修改)
<asp:CheckBox ID="CheckBox1" runat="server" ToolTip='<%# Eval("JY_ID") %>' Checked='<%# (Eval("JY_IsUser").ToString() == "0") ? false: true %>' AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged" />
2.進(jìn)行分頁(yè)
?。ㄗⅲ罕匦柚匦陆壎ú樵円淮螖?shù)據(jù))
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex; //得用GridView的分頁(yè)
setData();
}
3.對(duì)數(shù)據(jù)進(jìn)行編輯
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex; //得到要編輯的行
setData();
}
4.取消更新操作
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
setData();
}
5. GridView綁定數(shù)據(jù)
gvList.DataSource = ds;
gvList.DataKeyNames = new string[] { "id" }; //加上這個(gè)id,以便在進(jìn)行其它操作時(shí)得到
gvList.DataBind();
protected void gvList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = int.Parse(gvList.DataKeys[e.RowIndex].Value.ToString()); //這個(gè)就是在刪除操作中得到
//int id =Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[0].Text); //這種方法也可以得到
FriendLink.Delete(id);
GetList();
}
6 .對(duì)數(shù)據(jù)進(jìn)行更新(數(shù)據(jù)庫(kù))
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int id = Convert.ToInt32(this.GridView1.Rows[e.RowIndex].Cells[0].Text); //得到當(dāng)前要修改的ID
Model.BM_FirstTitle model = bll.ExecuteQuery(id) as Model.BM_FirstTitle; //得到要修改的數(shù)據(jù)的model
model.BM_FirstName = ((TextBox)(this.GridView1.Rows[e.RowIndex].FindControl("textBox2"))).Text; //model中要修改的數(shù)據(jù)
bll.ExecuteUpdate(model);
this.GridView1.EditIndex = -1;
setData();
}
如對(duì)本文有疑問(wèn),請(qǐng)?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答?。?點(diǎn)擊進(jìn)入論壇