I have created two buttons on the same page with rowcommand
& rowarguements
,
however, only one of it work fine, I have no idea why "Unexpected error' box is prompted when I tried to click another button. (btnInterview is working fine, btnContact
is not working)
Not just error msg is prompted, btnContact
cannot firing the event in rowcommand
either.
Code below(.aspx part):
<asp:GridView ID="GridView2" runat="server" AllowPaging="True"
EmptyDataText="No Sample is found"
OnPageIndexChanging="GridView1_PageIndexChanging"
PageSize="20"
OnSorting="GridView1_Sorting" OnDataBound="GridView1_DataBound"
OnRowCommand="GridView1_RowCommand" Width="100%" AllowSorting="True" OnRowCreated="GridView1_RowCreated">
<RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
<Columns>
<asp:TemplateField HeaderText="Phone Interview">
<ItemTemplate>
<asp:Button ID="btninterview" runat="server" Text="Interview" CommandName="btninterview_Click"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CssClass="intBtn" />
<asp:HiddenField runat="server" ID="hidid" Value='<%# Bind("Id")%>' />
<asp:HiddenField runat="server" ID="hidProject" Value='<%# Bind("Project")%>' />
<asp:HiddenField ID="hidEnablebtn" runat="server" Value='<%# Bind("enableButton")%>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone Interview">
<ItemTemplate>
<asp:Button ID="btnContact" runat="server" Text="Contact" CommandName="btncontact_Click"
CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" CssClass="intBtn" />
<asp:HiddenField ID="hidVisibleBtn" runat="server" Value='<%# Bind("visibleButton")%>' />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Code below(c# part):
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e){
Button btn = (Button)sender;
switch (btn.CommandName)
{
case "btninterview_Click":
//do sth1
break;
case "btncontact_Click":
//do sth2
break;
}
}