Domanda

I want a button in the Header of my Gridview and a checkbox field in the row of that header.

I was hoping the following code will work. However, this is not working. I just see "Remove" text in my header and when I click it nothing happens.

Am I doing something wrong?

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="false" CellPadding="4" ForeColor="#333333" 
                    GridLines="None" OnRowCommand="Gridview2_RowCommand">
                    <Columns>

                    <asp:BoundField DataField="fname" HeaderText="First Name" />
                    <asp:BoundField DataField="mname" HeaderText="Middle Name" />
                    <asp:BoundField DataField="lname" HeaderText="Last Name" />
                    <asp:TemplateField HeaderText="Remove">
                    <ItemTemplate>

                    <asp:CheckBox ID="checkselect" runat="server" />

                    </ItemTemplate>
                     <asp:HeaderTemplate>

                    <asp:LinkButton ID="LinkButton1" runat="server" CommandName="Split">sort</asp:LinkButton>

                     </asp:HeaderTemplate>
                    </asp:TemplateField>
                    </Columns> </Gridview>

The Even for Row Command

protected void Gridview2_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Split")
        {
            Response.Write("I was clicked");
        }
    }

Can someone help me with this?

È stato utile?

Soluzione

I was using the wrong tab prefix. The header template is simply

 <HeaderTemplate> not <asp:HeaderTemplate>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top