2

Here is the ASP

<asp:TemplateField>
    <ItemTemplate>
        <asp:ImageButton ID="button" ButtonType="Image" ImageUrl="~/Images/lock.png" text="Lock Customer" CommandName="lock" runat="server" />
    </ItemTemplate>
</asp:TemplateField>
<asp:ButtonField ButtonType="Image" ImageUrl="~/Images/lock_open.png" CommandName="unlock" runat="server" />

I did it two different ways based on research. The works, but I cannot get the tooltip to work.

the works, but when I press it to perform "lock" command, I get the following error:

System.FormatException: Input string was not in a correct format

Here is the cs:

Queries Q = new Queries();

string cmd = e.CommandName.ToString();
if (cmd == "unlock")
{
    int index = Convert.ToInt32(e.CommandArgument);
    GridViewRow row = Gridview1.Rows[index];
    string arg = row.Cells[3].Text.ToString();
    int c = Convert.ToInt32(arg);
    Q.UpdateRecord("UPDATE [tAccounts] SET [Status] = 'Good' WHERE [contractID] = " + c);
    Search();
}

if (cmd == "lock")
{
    int index = Convert.ToInt32(e.CommandArgument);
    GridViewRow row = Gridview1.Rows[index];
    string arg = row.Cells[3].Text.ToString();
    int c = Convert.ToInt32(arg);
    Q.UpdateRecord("UPDATE [tAccounts] SET [Status] = 'Locked' WHERE [contractID] = " + c);
    Search();
}

The line "int index = Convert.ToInt32(e.CommandArgument) ... e.CommandArgument is NULL on cmd == lock, but not on cmd == unlock.

All I want to do is add a tooltip to my buttonfield type: image.

2 Answers 2

1

The row index is automatically added to the command argument for a ButtonField, but not a TemplateField (or any other kind of field). You'll have to do it manually by setting the CommandArgument property on your ImageButton:

<asp:ImageButton ID="button"
    ButtonType="Image"
    ImageUrl="~/Images/lock.png"
    text="Lock Customer"
    CommandName="lock"
    CommandArgument="<%# Container.DataItemIndex%>"
    runat="server"
/>

source (see note at bottom of "Remarks")

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

Comments

0

Take a look at bootstrap, there you can find ways to add tooltips on varoius elements.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.