简体   繁体   English

如何在编辑项目模板上绑定下拉列表编辑模式在网格视图中发生

[英]how to bind drop down list at edit item template Edit mode occurs in grid view

i just want to bind two drop down list dynamically when grid view in row editing mode. 我只想在行编辑模式下的网格视图中动态绑定两个下拉列表。 here i declares one code block that dynamically fetches that row state and binds up those two drop down list. 在这里,我声明了一个代码块,该代码块动态获取该行状态并绑定了这两个下拉列表。

here is code : 这是代码:

  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());
                    }
                }
            }
..................
}

Is this right method to binds drop down list at row editing mode. 这种在行编辑模式下绑定下拉列表的正确方法。

please help me.... 请帮我....

很好。但是还有其他方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM