帮我看下这段代码哪里出错了?? gridview中点击编辑,再点击添加之后,gridview的编辑行和添加行都出来!如何取消编辑行????
if (e.CommandName == "Add")
{
if (this.dgvProductList.FooterRow == null)
{ }
else
{
string catName = dplCategoryList.SelectedItem.Text;
Category cat = categoryManager.GetCategoryBycategoryName(catName);
int catId = cat.CategoryId;
string prosql = "select * from productInfo where categoryId=" + catId;
this.dgvProductList.DataSource = productManager.GetProductsByCategoryId(prosql, catId);
this.dgvProductList.DataBind(); DropDownList dropDepart = this.dgvProductList.FooterRow.FindControl("dplDepart") as DropDownList;
dropDepart.DataSource = DepartmentManager.GetAll();
dropDepart.DataTextField = "departName";
dropDepart.DataValueField = "departId";
dropDepart.DataBind(); dropDepart.Items[0].Text = this.dplDepartList.SelectedItem.Text;
string departName = dropDepart.SelectedItem.Text.ToString();
Department depart = DepartmentManager.GetDepartIdByDepartName(departName);
if (depart != null)
{
int departId = depart.DepartId;
string sql = "SELECT categoryId,categoryName,categoryName displayName,categoryDescription,CNcategoryDescription,categoryImage,category.departId,DepartInfo.DepartName,parentcat,[order],active,categoryShortName FROM category inner join DepartInfo on category.DepartId=DepartInfo.DepartId WHERE category.departId ='" + departId + "' ORDER BY category.[order] ASC, category.categoryName ASC";
DropDownList dropcat = this.dgvProductList.FooterRow.FindControl("cateDpl") as DropDownList;
dropcat.DataSource = categoryManager.GetCategoryListByDepartId(departId, sql);
dropcat.DataTextField = "categoryName";
dropcat.DataValueField = "categoryId";
dropcat.DataBind();
dropcat.Items[0].Text = this.dplCategoryList.SelectedItem.Text;
DropDownList dropcat2 = this.dgvProductList.FooterRow.FindControl("dplCat2") as DropDownList;
dropcat2.DataSource = categoryManager.GetCategoryListByDepartId(departId, sql);
dropcat2.DataTextField = "categoryName";
dropcat2.DataValueField = "categoryId";
dropcat2.DataBind();
dropcat2.Items[0].Text = this.dplCategoryList.SelectedItem.Text;
this.dgvProductList.FooterRow.Visible = true;
}
}
this.nullShow.Visible = false;
int a= this.dgvProductList.EditIndex;// 测试这段代码的编辑行为0
this.dgvProductList.EditIndex = -1;//然后赋值为-1 取消编辑行
int b = this.dgvProductList.EditIndex;//断点显示值为-1}上面的测试之后 this.dgvProductList.EditIndex 显示为-1. 但是仍旧取消不了编辑行?? 为什么??? 帮忙看一下吧。谢谢!
if (e.CommandName == "Add")
{
if (this.dgvProductList.FooterRow == null)
{ }
else
{
string catName = dplCategoryList.SelectedItem.Text;
Category cat = categoryManager.GetCategoryBycategoryName(catName);
int catId = cat.CategoryId;
string prosql = "select * from productInfo where categoryId=" + catId;
this.dgvProductList.DataSource = productManager.GetProductsByCategoryId(prosql, catId);
this.dgvProductList.DataBind(); DropDownList dropDepart = this.dgvProductList.FooterRow.FindControl("dplDepart") as DropDownList;
dropDepart.DataSource = DepartmentManager.GetAll();
dropDepart.DataTextField = "departName";
dropDepart.DataValueField = "departId";
dropDepart.DataBind(); dropDepart.Items[0].Text = this.dplDepartList.SelectedItem.Text;
string departName = dropDepart.SelectedItem.Text.ToString();
Department depart = DepartmentManager.GetDepartIdByDepartName(departName);
if (depart != null)
{
int departId = depart.DepartId;
string sql = "SELECT categoryId,categoryName,categoryName displayName,categoryDescription,CNcategoryDescription,categoryImage,category.departId,DepartInfo.DepartName,parentcat,[order],active,categoryShortName FROM category inner join DepartInfo on category.DepartId=DepartInfo.DepartId WHERE category.departId ='" + departId + "' ORDER BY category.[order] ASC, category.categoryName ASC";
DropDownList dropcat = this.dgvProductList.FooterRow.FindControl("cateDpl") as DropDownList;
dropcat.DataSource = categoryManager.GetCategoryListByDepartId(departId, sql);
dropcat.DataTextField = "categoryName";
dropcat.DataValueField = "categoryId";
dropcat.DataBind();
dropcat.Items[0].Text = this.dplCategoryList.SelectedItem.Text;
DropDownList dropcat2 = this.dgvProductList.FooterRow.FindControl("dplCat2") as DropDownList;
dropcat2.DataSource = categoryManager.GetCategoryListByDepartId(departId, sql);
dropcat2.DataTextField = "categoryName";
dropcat2.DataValueField = "categoryId";
dropcat2.DataBind();
dropcat2.Items[0].Text = this.dplCategoryList.SelectedItem.Text;
this.dgvProductList.FooterRow.Visible = true;
}
}
this.nullShow.Visible = false;
int a= this.dgvProductList.EditIndex;// 测试这段代码的编辑行为0
this.dgvProductList.EditIndex = -1;//然后赋值为-1 取消编辑行
int b = this.dgvProductList.EditIndex;//断点显示值为-1}上面的测试之后 this.dgvProductList.EditIndex 显示为-1. 但是仍旧取消不了编辑行?? 为什么??? 帮忙看一下吧。谢谢!
需要重新设置 DataSource 属性,并且调用 DataBind() 方法。
You said has nothing to do with my issues!