0

I have the following GridView in which I have a select button in the first column that selects the row.

I want to put another similar (custom/user defined) button in a new column right next to select button called "Compute". How can I do that?

<asp:GridView ID="GridViewSavingsTracker" AutoGenerateColumns="false" runat="server" OnRowCommand="GridViewSavingsTracker_RowCommand">
    <Columns>
        <asp:CommandField ShowSelectButton="true" />
        <asp:BoundField DataField="creditorName" HeaderText="Creditor Name" />
        <asp:BoundField DataField="amount" HeaderText="Principal Amount" />
        <asp:BoundField DataField="interestRate" HeaderText="Interest Rate" />   
    </Columns>
</asp:GridView>

1 Answer 1

1
<asp:ButtonField Text="Text_on_the_Button" CommandName="Command1" ButtonType="Link" />

Command_Name = Gets or Sets a string that represents the action to perform when a button in a ButtonField object is clicked.

And on server side:

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if(e.CommandName=="Command1")
    {
        // What you want to do when the button is clicked.
    }
}

Source: https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.buttonfield(v=vs.110).aspx

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.