0
我編輯的網格視圖,如果我點擊任何一行編輯說,「X」,它在編輯模式下打開,但是如果我點擊任何其他行,說「Y」,「X」應取消編輯。但在點擊「y」後,在我的代碼中,兩行都保持編輯模式。網格視圖編輯問題
protected void gvViewAdmins_RowEditing(object sender, GridViewEditEventArgs e)
{
gvViewAdmins.EditIndex = e.NewEditIndex;
Label lblEmailId = gvViewAdmins.Rows[e.NewEditIndex].FindControl("gvlblEmail") as Label;
lblEmailId.Visible = false;
ViewState["currentEmailId"] = lblEmailId.Text;
TextBox textboxEmailId = gvViewAdmins.Rows[e.NewEditIndex].FindControl("gvtbEmailId") as TextBox;
textboxEmailId.Text = ViewState["currentEmailId"].ToString();
textboxEmailId.Visible = true;
Label lblRole = gvViewAdmins.Rows[e.NewEditIndex].FindControl("gvlblRole") as Label;
lblRole.Visible = false;
ViewState["currentRole"] = lblRole.Text;
DropDownList dropdownRoles = gvViewAdmins.Rows[e.NewEditIndex].FindControl("gvddlRoles") as DropDownList;
this.PopulateRole(dropdownRoles);
dropdownRoles.Visible = true;
this.SelectRoleDropDownValue(dropdownRoles);
LinkButton lbtnUpdate = gvViewAdmins.Rows[e.NewEditIndex].FindControl("lbtnUpdate") as LinkButton;
LinkButton lbtnCancel = gvViewAdmins.Rows[e.NewEditIndex].FindControl("lbtnCancel") as LinkButton;
LinkButton lbtnEdit = gvViewAdmins.Rows[e.NewEditIndex].FindControl("lbtnEdit") as LinkButton;
lbtnUpdate.Visible = true;
lbtnCancel.Visible = true;
lbtnEdit.Visible = false;
}
我的代碼有什麼問題?
好了,現在我改變了我的代碼按你的樣品。但是有一個下拉列表,只有在編輯模式下才能看到。如果我將它保存在中,findControl的代碼在代碼後面不起作用。 'DropDownList dropdownRoles = gvViewAdmins.Rows [e.NewEditIndex] .FindControl(「gvddlRoles」)爲DropDownList; this.PopulateRole(dropdownRoles); dropdownRoles.Visible = true; this.SelectRoleDropDownValue(dropdownRoles);'這裏下拉顯示空值,而調試。 –
user1181942
2012-04-03 05:11:56
我知道了......我必須在PreRender事件中找到控件,而不是在行Edititng中......感謝您的幫助:) – user1181942 2012-04-03 05:56:24
您還可以在行數據綁定事件中查找控件,方法是檢查是否(e.Row.RowIndex == gDViewAdmins.EditIndex){DropDownList dropdownRoles = gvViewAdmins.Rows [e.NewEditIndex] .FindControl(「gvddlRoles」)作爲DropDownList},它檢查當前綁定行是編輯行。另外,沒有必要寫「dropdownRoles.Visible = true;」。無論如何它都會顯示它。 – 2012-04-05 04:43:58