C# 如何在Gridview中将工具提示正确添加为悬停按钮
这是ASPC# 如何在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: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"
/>