gridview 下拉DropDownList 更新操作
来源:互联网 发布:nginx 不能通过ip访问 编辑:程序博客网 时间:2024/05/16 17:01
前台代码
后台代码public partial class GridView_DropDownList : System.Web.UI.Page
{
private DataAccess da = SingleTon<DataAccess>.Instance;
protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
BindGridView();
}
}
private void BindGridView()
{
DataTable dt = da.GetTable("select name,address,age,country_id,country_name ,id from userinfo ,country where country_id=country ");
grid.DataSource = dt;
grid.DataBind();
}
/// <summary>
/// command命令操作gridview
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "test")
{
string id= e.CommandArgument.ToString();
Response.Write(" <script> javascript:alert( '" + id + "'); </script> ");
Response.Flush();
}
}
private void BindDropDownListCountry(DropDownList drp)
{
DataTable dt = da.GetTable("select country_id,country_name from country");
drp.DataSource = dt;
drp.DataValueField="country_id";
drp.DataTextField = "country_name";
drp.DataBind();
}
protected void grid_RowEditing(object sender, GridViewEditEventArgs e)
{
grid.EditIndex = e.NewEditIndex;
BindGridView();
}
protected void grid_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grid.EditIndex = -1;
BindGridView();
}
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && ((e.Row.RowState & DataControlRowState.Edit) > 0))
{
DropDownList drp = e.Row.FindControl("dd_country") as DropDownList;
BindDropDownListCountry(drp);
drp.SelectedValue = (e.Row.FindControl("hdd_countryid") as HiddenField).Value ;
}
}
/// <summary>
/// 更新
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void grid_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
DropDownList drp = grid.Rows[e.RowIndex].FindControl("dd_country") as DropDownList;
string country_ID=drp.SelectedValue;
string id = grid.DataKeys[e.RowIndex].Value.ToString();
string msg = string.Empty;
if (da.ExcuteSql("update userinfo set country='"+country_ID+"' where id='" + id + "'", out msg))
{
grid.EditIndex = -1;
BindGridView();
}
}
- gridview 下拉DropDownList 更新操作
- GridView中DropDownList更新
- GridView与DropDownList结合使用进行更新操作
- GridView中的DropDownList操作
- GridView内嵌DropDownList操作
- GridView和下拉菜单DropDownList结合
- GridView和下拉菜单DropDownList结合
- 4.GridView和下拉菜单DropDownList结合:
- gridview--嵌套dropdownlist 然后更新列
- GridView操作大全 无代码分页排序 正反双向排序 和下拉菜单DropDownList结合,选中,编辑,取消,删除
- GridView对DropDownList控件操作实例
- ASP.NET GridView里操作DropDownList
- DropDownList下拉列表的基础操作
- asp.net GridView和下拉菜单DropDownList结合
- GridView更新操作问题
- GridView里使用 DropDownList 更新数据列,不需要写一句代码
- Gridview与DropDownList联动添加数据实时更新
- 利用AJAX实现DropDownList与GridView做实时更新
- 设计模式之创建型模式
- 浅谈C++和Java的设计差异
- 内存管理之数组
- 一次谷歌面试趣事【转】
- 新浪微博技术架构分析
- gridview 下拉DropDownList 更新操作
- redhat fedora的串口
- php自动加载源文件
- 一个XNA程序引发的连锁问题
- Win7下:编译器错误信息: CS0016: 未能写入输出文件“c:/Windows/Microsoft.NET/Framework……”
- windows环境下,msys+mingw 编译clapack 3.2.1
- 在ejb的会话bean(session bean)中使用数据源(DataSource)!!!
- 关于GTOPO30命名
- css实现强制不换行/自动换行/强制换行