GridView 自定义简单操作

usingSystem;
usingSystem.Data;
usingSystem.Configuration;
usingSystem.Collections;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.WebControls.WebParts;
usingSystem.Web.UI.HtmlControls;
publicpartialclassSY16:System.Web.UI.Page
...{
protectedvoidPage_Load(objectsender,EventArgse)
...{
if(Page.IsPostBack)
return;
DataBind();

}

protectedvoidGridView_pubs_RowDeleting(objectsender,GridViewDeleteEventArgse)
...{
intSelectedIndex=e.RowIndex;
stringpub_id=GridView_pubs.Rows[SelectedIndex].Cells[1].Text;
BLL.AccessDataBasedb
=newBLL.AccessDataBase();
db.Delete(pub_id);
DataBind();
Response.Write(SelectedIndex.ToString()
+pub_id);

}

protectedvoidButton_query_Click(objectsender,EventArgse)
...{
BLL.AccessDataBasedb
=newBLL.AccessDataBase();
DataSetds
=db.Query(TextBox_query.Text.ToString());
GridView_pubs.DataSource
=ds;
GridView_pubs.DataBind();
}

protectedvoidGridView_pubs_RowEditing(objectsender,GridViewEditEventArgse)
...{
GridView_pubs.EditIndex
=e.NewEditIndex;
DataBind();

}

protectedvoidGridView_pubs_RowUpdating(objectsender,GridViewUpdateEventArgse)
...{
intEditIndex=e.RowIndex;
Response.Write(EditIndex.ToString());
stringpub_id=((TextBox)GridView_pubs.Rows[EditIndex].Cells[1].Controls[0]).Text;
stringpub_name=((TextBox)GridView_pubs.Rows[EditIndex].Cells[2].Controls[0]).Text;
stringcity=((TextBox)GridView_pubs.Rows[EditIndex].Cells[3].Controls[0]).Text;
stringstate=((TextBox)GridView_pubs.Rows[EditIndex].Cells[4].Controls[0]).Text;
stringcountry=((TextBox)GridView_pubs.Rows[EditIndex].Cells[5].Controls[0]).Text;
BLL.AccessDataBasedb
=newBLL.AccessDataBase();
db.Update(pub_id,pub_name,city,state,country);
GridView_pubs.EditIndex
=-1;
DataBind();
}

protectedvoidGridView_pubs_RowCancelingEdit(objectsender,GridViewCancelEditEventArgse)
...{
GridView_pubs.EditIndex
=-1;
DataBind();
}

privatevoidDataBind()
...{
BLL.AccessDataBasedb
=newBLL.AccessDataBase();
DataSetds
=db.ShowData();
GridView_pubs.DataSource
=ds;
GridView_pubs.DataBind();
}

}

阅读更多

没有更多推荐了,返回首页