Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在网格视图中以编辑项模板编辑模式绑定下拉列表_C#_Asp.net 4.0 - Fatal编程技术网

C# 如何在网格视图中以编辑项模板编辑模式绑定下拉列表

C# 如何在网格视图中以编辑项模板编辑模式绑定下拉列表,c#,asp.net-4.0,C#,Asp.net 4.0,我只想在网格视图处于行编辑模式时动态绑定两个下拉列表。在这里,我声明了一个动态获取该行状态并绑定这两个下拉列表的代码块 以下是代码: protected void GV_ViewCustomers_RowDataBound(object sender, GridViewRowEventArgs e) { ............... if (e.Row.RowType == DataControlRowType.DataRow && (e

我只想在网格视图处于行编辑模式时动态绑定两个下拉列表。在这里,我声明了一个动态获取该行状态并绑定这两个下拉列表的代码块

以下是代码:

  protected void GV_ViewCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
    {
          ...............
    if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
            {
                using (DataClassesDataContext db = new DataClassesDataContext())
                {
                    DropDownList dl = (DropDownList)e.Row.FindControl("DDL_Types1");
                    dl.DataSource = db.PartyTypes.Select(t => t).ToList();
                    dl.DataBind();
                    dl.SelectedValue = DataBinder.Eval(e.Row.DataItem, "type_id").ToString();
                    DropDownList dl1 = (DropDownList)e.Row.FindControl("DDL_CountryNames1");
                    dl1.DataSource = db.Countries.Select(c => c).ToList();
                    if (!string.IsNullOrEmpty(DataBinder.Eval(e.Row.DataItem, "country_id").ToString()))
                    {
                        dl1.SelectedValue = DataBinder.Eval(e.Row.DataItem, "country_id").ToString();
                        DropDownList dl2 = (DropDownList)e.Row.FindControl("DDL_StateNames1");
                        dl2.DataSource = db.States.Where(s => s.country_id.Equals(int.Parse(DataBinder.Eval(e.Row.DataItem, "country_id").ToString()))).Select(s => s).ToList();
                        dl2.DataBind();
                    }
                    DataRowView rowView1 = (DataRowView)e.Row.DataItem;
                    if (rowView1["UserOFC"] != null)
                    {
                        (e.Row.FindControl("chk_UserOFC1") as CheckBox).Checked = Convert.ToBoolean(e.Row.DataItem.Equals("UserOFC").ToString());
                    }
                    if (rowView1["UserVAT"] != null)
                    {
                        (e.Row.FindControl("chk_UserVAT1") as CheckBox).Checked = Convert.ToBoolean(e.Row.DataItem.Equals("UserVAT").ToString());
                    }
                    if (rowView1["UserINV"] != null)
                    {
                        (e.Row.FindControl("chk_UserINV1") as CheckBox).Checked = Convert.ToBoolean(e.Row.DataItem.Equals("UserINV").ToString());
                    }
                    if (rowView1["UserNone"] != null)
                    {
                        (e.Row.FindControl("chk_UserNone1") as CheckBox).Checked = Convert.ToBoolean(e.Row.DataItem.Equals("UserNone").ToString());
                    }
                }
            }
..................
}
这是在行编辑模式下绑定下拉列表的正确方法


请帮助我……

这很好。但是还有其他一些方法。

您对此有任何错误或问题吗?没有,这不会绑定此下拉列表。我一直怀疑这不是在行编辑模式下绑定下拉列表和复选框的正确方法。我认为您处于行编辑事件中,所以这也很好。您可以在RowDataBinding事件中通过标识网格的编辑行来执行此绑定。再次查看问题我想我错过了上面的事件行。是的。。该事件也是正确的。还有另一个名为RowDataBinding的事件。您也可以在该事件中进行绑定。你的努力很好正如我在上述评论中提到的。您可以在RowDataBinding事件中绑定数据。而且,如果使用jquery或java脚本绑定数据,则可以使用javascript或jquery方法绑定数据。