首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > PowerDesigner >

GridView中DropDownList的使用

2012-09-07 
GridView中DropDownList的应用在GridView中添加一个字段,并且需要在编辑的时候以DropDownList的形式展现出

GridView中DropDownList的应用

在GridView中添加一个字段,并且需要在编辑的时候以DropDownList的形式展现出来,同时要求展示的时候要求显示的数据保存不变。

首先,点击Gridview右上角Gridview 任务 (Gridview Tasks),选择编辑列(Edit Colums),将某字段(比如Place)转化为模板列(Convert this field into a TemplateField )。

然后,进入前台代码 xxx.aspx页面,对该字段的列进行编辑:

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)        {            string script = "";            string bookingID = GridView1.DataKeys[e.RowIndex].Value.ToString();            DropDownList ddl = (DropDownList)GridView1.Rows[e.RowIndex].FindControl("dropdlst_p");            if (DBHandler.UpdateCPList(bookingID, ddl.SelectedValue, userID))//此方法作用是判断是否更新成功,取出droplst_p的选择项进行判断            {                script = "alert('Update Successfully!');";            }            else            {                script = "alert('Update Failed!');";            }            ScriptManager.RegisterStartupScript(this, typeof(Page), "startup", script, true);            gridRpt.EditIndex = -1;//取消编辑状态            BindGV();//重新绑定GridView数据源        }



热点排行