这可能看起来像重复,但我不这么认为。我已经搜索了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