OnRowCommand 事件有时不会触发
本文关键字:事件 OnRowCommand | 更新日期: 2023-09-27 18:32:59
我有带有ButtonField的GridView:
<asp:GridView ID="activitygrid" runat="server" CssClass="EU_DataTable" class="ui-body-d" OnRowCommand="activitygrid_RowCommand1" AutoGenerateColumns="False" OnSelectedIndexChanged="activitygrid_SelectedIndexChanged" ShowHeaderWhenEmpty="True" >
<asp:ButtonField CommandName="cmdRegister" Text="register now" ControlStyle-CssClass="table-stripe" HeaderText="register" ButtonType="Button" ControlStyle-Height="20px" >
<ControlStyle CssClass="table-stripe"></ControlStyle>
</asp:ButtonField>
页面加载代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
BindData();
}
else
{
BindDataSecondTime();
}
}
行命令代码:
protected void activitygrid_RowCommand1(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "cmdRegister")
{
registerActivities.Add(relActivities[index]);
//Update the sum
CurrentSum += relActivities[index].ActivityPrice;
lblSum.Text = CurrentSum.ToString();
selectedactivitygrid.DataSource = registerActivities;
selectedactivitygrid.DataBind();
relActivities.Remove(relActivities[index]);
activitygrid.DataSource = relActivities;
activitygrid.DataBind();
}
}
问题是当我单击按钮时,有时会触发事件(通常是当我单击按钮中间时),有时不会.
请帮忙。
我删除了ControlStyle-Height="20px"
并解决了。