模板字段的标头模板中的图像按钮不起作用

时间:2013-02-18 15:02:52

标签: asp.net vb.net gridview header templatefield

我看了一眼,虽然似乎有很多类似的问题,但我找不到有帮助的答案。

我在模板字段的标题中有一个图像按钮,但它不希望被智能感知识别,当我点击它时它也不起作用(它只是坐在那里,看起来很茫然)。有什么建议吗?

aspx文件

<asp:GridView ID="gvMenuItems" runat="server" AutoGenerateColumns="false" DataKeyNames="MIID" CssClass="no-border" GridLines="None" CellPadding="2" CellSpacing="0" RowStyle-VerticalAlign="NotSet" Width="300px">
<RowStyle CssClass="gvRow" />
<AlternatingRowStyle CssClass="gvAltRow" />
<Columns>
    <asp:TemplateField>
        <HeaderTemplate>
            <asp:ImageButton runat="server" ID="btnCreateRootMI" OnCommand="gvMenuItems_RowCommand" CommandName="createMI" ImageUrl="images/icon_greencross.png" ToolTip="Add new menu item at the menu root" />  Menu Text
        </HeaderTemplate>
        <ItemTemplate>
            <%# Eval("Text")%>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:ButtonField CommandName="AddItem" ButtonType="Image" ImageUrl="images/icon_greencross.png" ItemStyle-Width="20px" ItemStyle-HorizontalAlign="Center" />
    <asp:ButtonField CommandName="EditItem" ButtonType="Image" ImageUrl="images/icon_edit.png" ItemStyle-Width="20px" ItemStyle-HorizontalAlign="Center" />
    <asp:ButtonField CommandName="DeleteItem" ButtonType="Image" ImageUrl="images/icon_delete.png" ItemStyle-Width="20px" ItemStyle-HorizontalAlign="Center" />
</Columns>

vb.net文件

Protected Sub gvMenuItems_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gvMenuItems.RowCommand
    Dim rowIndex As Integer
    Dim id As String
    If String.IsNullOrEmpty(e.CommandArgument) Then
        rowIndex = 0
        id = "0"
    Else
        rowIndex = Integer.Parse(e.CommandArgument)
        id = gvMenuItems.DataKeys(rowIndex).Value
    End If

    If e.CommandName = "EditItem" Then
        ifEditMenuItem.Attributes("src") = rootURL & "MenuItems/Edit.aspx?MIID=" & id.ToString & "&Application=" & previewID
    ElseIf e.CommandName = "DeleteItem" Then
        Literal1.Text += SQLDB.executeSqlCUD("UPDATE MenuItems SET fkParent = (SELECT fkParent FROM MenuItems WHERE MIID = " & id.ToString & ") WHERE fkParent = " & id.ToString, adminDB)
        Literal1.Text += SQLDB.executeSqlCUD("DELETE FROM MenuItems WHERE MIID = " & id.ToString, adminDB)
        Response.Redirect(fqPageUrl)
    ElseIf e.CommandName = "AddItem" Then
        ifEditMenuItem.Attributes("src") = rootURL & "MenuItems/Insert.aspx?MenuItem=" & id.ToString & "&Application=" & previewID
    ElseIf e.CommandName = "createMI" Then
        ifEditMenuItem.Attributes("src") = rootURL & "MenuItems/Insert.aspx?Application=" & previewID
    End If
End Sub

0 个答案:

没有答案