locked
How to add a Text box in the Gridview Header RRS feed

  • Question

  • User465603007 posted

     How do i add a text box in the grid view header row, such a way that for each column in the in the GridView Row I have a text box in the Gridview Header.

    Also help me with some reference sites, if any.

    Thanks in advance. 

     

    Wednesday, July 4, 2007 4:06 PM

Answers

  • User-1426124666 posted

    How about this:

     

    Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
            ' Check the header type
            If e.Row.RowType = DataControlRowType.Header Then
                Dim litHeader As Literal
                Dim txtSearch As TextBox
    
                ' loop through each cell
                For i As Integer = 0 To (e.Row.Cells.Count - 1)
                    litHeader = New Literal
                    txtSearch = New TextBox
    
                    ' get the current header text
                    litHeader.Text = e.Row.Cells(i).Text & "<br />"
    
                    ' add the header text plus a new textbox
                    e.Row.Cells(i).Controls.Add(litHeader)
                    e.Row.Cells(i).Controls.Add(txtSearch)
                Next
    
            End If
        End Sub
      
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 4, 2007 4:38 PM
  • User-992958275 posted

    Click the arrow at the top right corner of the gridview to show the smart tags.

    Then click on Edit Templates

    Select header Template from the dropdownlist

    From the Toolbox add textbox control into header template field

    Click end template editing

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2007 12:14 AM
  • User-528979147 posted

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" UseAccessibleHeader="True">

     

    <Columns>

    <asp:TemplateField HeaderText="DateField" SortExpression="DateField">

    <HeaderTemplate>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></HeaderTemplate>

    <EditItemTemplate>

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DateField") %>'></asp:TextBox>

    </EditItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label1" runat="server" Text='<%# Bind("DateField") %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    <asp:TemplateField HeaderText="Event" SortExpression="Event">

    <HeaderTemplate>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></HeaderTemplate>

    <EditItemTemplate>

    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Event") %>'></asp:TextBox>

    </EditItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Event") %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    </Columns>

    </asp:GridView>

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Database1.mdb"

    SelectCommand="SELECT * FROM [Table1]"></asp:AccessDataSource>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2007 3:02 AM

All replies

  • User-1426124666 posted

    How about this:

     

    Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
            ' Check the header type
            If e.Row.RowType = DataControlRowType.Header Then
                Dim litHeader As Literal
                Dim txtSearch As TextBox
    
                ' loop through each cell
                For i As Integer = 0 To (e.Row.Cells.Count - 1)
                    litHeader = New Literal
                    txtSearch = New TextBox
    
                    ' get the current header text
                    litHeader.Text = e.Row.Cells(i).Text & "<br />"
    
                    ' add the header text plus a new textbox
                    e.Row.Cells(i).Controls.Add(litHeader)
                    e.Row.Cells(i).Controls.Add(txtSearch)
                Next
    
            End If
        End Sub
      
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 4, 2007 4:38 PM
  • User-992958275 posted

    Click the arrow at the top right corner of the gridview to show the smart tags.

    Then click on Edit Templates

    Select header Template from the dropdownlist

    From the Toolbox add textbox control into header template field

    Click end template editing

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2007 12:14 AM
  • User-528979147 posted

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="AccessDataSource1" UseAccessibleHeader="True">

     

    <Columns>

    <asp:TemplateField HeaderText="DateField" SortExpression="DateField">

    <HeaderTemplate>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></HeaderTemplate>

    <EditItemTemplate>

    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DateField") %>'></asp:TextBox>

    </EditItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label1" runat="server" Text='<%# Bind("DateField") %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    <asp:TemplateField HeaderText="Event" SortExpression="Event">

    <HeaderTemplate>

    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></HeaderTemplate>

    <EditItemTemplate>

    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Event") %>'></asp:TextBox>

    </EditItemTemplate>

    <ItemTemplate>

    <asp:Label ID="Label2" runat="server" Text='<%# Bind("Event") %>'></asp:Label>

    </ItemTemplate>

    </asp:TemplateField>

    </Columns>

    </asp:GridView>

    <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/Database1.mdb"

    SelectCommand="SELECT * FROM [Table1]"></asp:AccessDataSource>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, July 5, 2007 3:02 AM