So I have a gridview where inside the FooterTemplate I have defineted a commandname for buttton Add. Here the code for that:
<asp:TemplateField>
<HeaderStyle Font-Size="XX-Small" Font-Names="Verdana" Font-Bold="True" VerticalAlign="Top"></HeaderStyle>
<FooterTemplate><asp:LinkButton CommandName="Insert" Text="Add credit" ID="btnAdd" OnClick="btnAdd_Click" Runat="server" Font-Size="XX-Small "
Font-Names="Verdana" Font-Bold="True" ForeColor="#5BB1E6" Width="7%"></asp:LinkButton>
</FooterTemplate>
</asp:TemplateField>
Just like this Add button I have another button called Edit and I want to put SQL statements for all these buttons in one function. I wanted to do something like this:
protected bool AddNewCredit()
if (e.Commandname == "Insert")
{
Do This}
if (e.Commandename == "Edit")
{
Do this
}
And so on. Problem is when I try to access e.rowcommand it doesn't catch commandname after e.
Help is appreciated to acheive my goal which is to be able to read the value of e.commandname in a function. Thanks a lot everyone :)
Change it to this:
then change your btnAdd_Click function to this:
If you want to catch CommandName and CommandArgument you need to use the OnCommand event, not OnClick.