我创建了一个gridview,根据查询结果显示员工列表。我在gridview中放了一些asp控件,比如checkbox和imagebuttons。我把OnRowCommand Event放到了gridview上。现在,当我点击该gridview中的按钮时,OnRowCommand事件没有触发。 请参阅此代码
<asp:GridView ID="gvSalaryChange" runat="server" HeaderStyle-CssClass="HeaderStyle"
RowStyle-CssClass="RowStyle" AlternatingRowStyle-CssClass="AlternatingRowStyle"
FooterStyle-CssClass="FooterStyleGrid" EmptyDataRowStyle-BackColor="White" AutoGenerateColumns="False"
EmptyDataText="No result were found." ShowFooter="true" DataKeyNames="EmployeeID" OnRowCreated="gvSalaryChange_RowCreated"
OnRowDataBound="gvSalaryChange_RowDataBound" OnRowCommand="gvSalaryChange_RowCommand" Width="100%">
<Columns>
<asp:TemplateField HeaderText="Select" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" OnCheckedChanged="chkSelect_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<table>
<tr>
<td>
<asp:ImageButton ID="btnApprove" runat="server"
ImageUrl="~/App_Resources/images/content/approve.png" CommandName="Approved" CausesValidation="false" />
</td>
<td>
<asp:ImageButton ID="btnDisApprove" runat="server"
ImageUrl="~/App_Resources/images/content/process-stop.png" CommandName="DisApproved" CausesValidation="false" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EmployeeName" HeaderText="Employee Name" />
<asp:BoundField DataField="Department" HeaderText="Department" />
<asp:BoundField DataField="Position" HeaderText="Position" />
<asp:BoundField DataField="Module" HeaderText="Reason for Salary Change" />
</Columns>
</asp:GridView>
protected void gvSalaryChange_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = int.Parse(e.CommandArgument.ToString());
if (e.CommandName == "Approve")
{
List<SalaryChangeEntity> entity = (List<SalaryChangeEntity>)ViewState["SalaryChangeView"];
long empID = (long)gvSalaryChange.DataKeys[index].Value;
_salaryChangeManager.InsertSalaryChange(entity.Where(k => k.EmployeeID == empID).Single());
}
if (e.CommandName == "DisApprove")
{
//string vendid = Convert.ToString(e.CommandArgument.ToString());
}
}