手机版

网站后台管理之数据列表绑定、删除和修改(17)

时间:2025-04-28   来源:未知    
字号:

后台代码主要包括初始化数据事件、编辑事件、修改事件和取消事件: //初始化下拉框数据事件

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {

if (e.Row.RowIndex < 0) return;

BLL.ArticleType articleTypeBll = new BLL.ArticleType(); DataSet ds = new DataSet(); ds = articleTypeBll.GetList("");

HiddenField hd = (HiddenField)e.Row.FindControl("HiddenFieldId");//获取主键值 BLL.Article articleBll = new BLL.Article(); Model.Article articleModel = new Model.Article();

articleModel = articleBll.GetModel(Convert.ToInt32(hd.Value)); //行的状态是: 编辑状态 或者 (交替行且是编辑状态) if(e.Row.RowState == DataControlRowState.Edit ||

e.Row.RowState == (DataControlRowState.Alternate | DataControlRowState.Edit)) {

DropDownList ddlType = e.Row.FindControl("ddlType") as DropDownList; if (ddlType != null) {

ddlType.DataValueField = "articleTypeId"; ddlType.DataTextField = "articleTypeName"; ddlType.DataSource = ds; ddlType.DataBind();

ddlType.Items.FindByValue(articleModel.articleTypeId.ToString()).Selected = true; } } }

//编辑事件

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e) {

GridView1.EditIndex = e.NewEditIndex; BindGridView(); }

//修改事件

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) {

GridViewRow myrow = GridView1.Rows[e.RowIndex];

HiddenField hd = (HiddenField)myrow.Cells[0].FindControl("HiddenFieldId");//获取主键值

TextBox txtTitle = (TextBox)myrow.Cells[2].FindControl("txtTitle");//获取标题

DropDownList ddlType = myrow.Cells[3].FindControl("ddlType") as DropDownList;//获取下拉框值

网站后台管理之数据列表绑定、删除和修改(17).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
×
二维码
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)