這可能看起來像重複,但我不這麼認爲。我已經搜索了stackoverflow,可能還不夠。GridView的OnRowCommand第一次沒有開通
這裏是我的挑戰:
<asp:LinkButton runat="server" ID="DeleteRow" CommandName="deleterow"
CommandArgument='<%# Eval("ID") %>' Text="Delete"
OnClientClick="return confirm('Are you sure you want to delete this record?');" />
如果您單擊鏈接的第一次,OnRowCommand不會被解僱。當你第二次點擊它時,它會起作用。
我看着源頭,我有這些差異。
//When you first load the page: the GUID is the PK for that row
1. javascript:__doPostBack('ctl00$content$gvSchoolClasses$58fd1759-f358-442e-bf73-2e9cedfc27e8$DeleteRow','')
//After the link was clicked the first time, the link changed and the ID empty, but works
2. javascript:__doPostBack('ctl00$content$gvSchoolClasses$ctl02$DeleteRow','')
我複製從asp:LinkButton
的href
兩個代碼之前和後,點擊。
出了什麼問題?我的頁面RowDataBound
上只有一個其他事件。
protected void gvSchoolClasses_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.ID = Guid.NewGuid().ToString();
}
protected void Page_Load(object sender, EventArgs e)
{
CheckAuthentication();
if (!Page.IsPostBack)
{
ClassesAcademicYearLabel.Text = "- Year " + Setting.Year;
//FillClassesList(); //filling some combo boxes. Have checked the codes here too
//FillLettersList(); //they didn't affect the Grid
FillGrid();
}
ClassErrorLabel.Visible = false;
}
介意分享你的'RowDataBound'事件處理代碼?我很好奇你爲什麼排除它作爲問題來源 – 2012-07-10 19:27:05
我相信裏面的代碼不應該影響linkButton。那影響了網格 – codingbiz 2012-07-10 19:30:20
哪裏調用了'gvSchoolClasses.DataBind()'? 'Page_Load'? – 2012-07-10 19:32:58