Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Gridview中将工具提示正确添加为悬停按钮_C#_Asp.net - Fatal编程技术网

C# 如何在Gridview中将工具提示正确添加为悬停按钮

C# 如何在Gridview中将工具提示正确添加为悬停按钮,c#,asp.net,C#,Asp.net,这是ASP <asp:TemplateField> <ItemTemplate> <asp:ImageButton ID="button" ButtonType="Image" ImageUrl="~/Images/lock.png" text="Lock Customer" CommandName="lock" runat="server" /> </ItemTemplate> </asp:TemplateF

这是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" />
以下是政务司司长的答覆:

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();
}
行“
int index=Convert.ToInt32(e.CommandArgument)
…e.CommandArgument在
cmd==lock
上为空,但在cmd==unlock上不为空


我想做的就是在我的按钮字段类型:image中添加一个工具提示。

看看引导程序,在那里你可以找到在varoius元素上添加工具提示的方法。

行索引自动添加到
按钮字段的命令参数中,而不是
模板字段(或任何其他类型的字段)。您必须通过在
ImageButton
上设置
CommandArgument
属性手动执行此操作:

<asp:ImageButton ID="button"
    ButtonType="Image"
    ImageUrl="~/Images/lock.png"
    text="Lock Customer"
    CommandName="lock"
    CommandArgument="<%# Container.DataItemIndex%>"
    runat="server"
/>
(参见“备注”底部的注释)

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