本文介绍了如何绑定上编辑(ImageButton的)单击GridView控件的EditItemTemplate的ASP.Net DropDownList控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我必须要求绑定在GridView控件的EditItemTemplate的ASP.Net DropDownList控件。
我有一个的CommandName =编辑下拉菜单也需要一个编辑的ImageButton从不同的表(目录)绑定,而不是通过网格绑定(详细信息)的表。

I have requirement to bind ASP.Net DropDownList control in EditItemTemplate of GridView.I have a edit imagebutton with commandname="Edit"also dropdown needs to be binded from different table(directory) and not the table through which grid is binded(details).

if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit && GridView1.EditIndex == e.Row.RowIndex)
 {
    DropDownList DStatusEdit = (DropDownList)e.Row.FindControl("DStatusEdit");
    string query = "select distinct status from directory";
    SqlCommand cmd = new SqlCommand(query);
    DStatusEdit.DataSource = GetData(cmd);
    DStatusEdit.DataTextField = "status";
    DStatusEdit.DataValueField = "status"; DStatusEdit.DataBind();
    DataStatusEdit.DataBind();
 }

在页面运行,但是当我点击编辑图像按钮dropdwn显示,但下拉没有数据绑定是空的。
我的gridview的是更新面板内。
我怎样才能做到这一点?
在我的情况应该DROPDOWNLIST被绑定内rowcommand但如何?

the page is running but when i click edit image button the dropdwn shows but no data in dropdown binded it is empty.My gridview is inside update panel.How can i achieve this?Should dropdownlist in my case be binded inside rowcommand but how?

推荐答案

code:试试这个

protected void gv_RowDataBound(object sender, GridViewEditEventArgs e)
    {
     if (e.Row.RowType == DataControlRowType.DataRow)
      {
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {
              DropDownList ddList= (DropDownList)e.Row.FindControl("DStatusEdit");
              //bind dropdownlist
              DataTable dt = con.GetData("select distinct status from directory");
              ddList.DataSource = dt;
              ddList.DataTextField = "YourCOLName";
              ddList.DataValueField = "YourCOLName";
              ddList.DataBind();

              DataRowView dr = e.Row.DataItem as DataRowView;
              //ddList.SelectedItem.Text = dr["YourCOLName"].ToString();
              ddList.SelectedValue = dr["YourCOLName"].ToString();
            }
       }
    }

刚才已经回答类似的问题Binding里面的GridView的dropdownlist EditItemTemplate中

查看博客文章:

View Blog Article : How to bind drop-down list inside gridview edit template

这篇关于如何绑定上编辑(ImageButton的)单击GridView控件的EditItemTemplate的ASP.Net DropDownList控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 14:58