Results 1 to 5 of 5

Thread: GridView Footer - need help

  1. #1

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Question GridView Footer - need help

    I have an application where user is able to select jobs which will show equipment ID and equipment hours.

    I am displaying a GridView that has a CommandField in the 1st column with a ShowSelectButton= True. The user is able to click the select button and a 2nd (detailed) GridView is shown. This works fine.

    I have added a Footer to my GridView. I show total equipment hours for the selection (looping through the Data Table). This work fine as well.

    Now, the 1st columnt is showing FooterText = "Select". I need to be able to click this column (same way I do in the GridView.Data) and in my code behing capture this click event.

    Mark Up Code:

    Code:
    <asp:GridView ID="GridView1" runat="server" Style="z-index: 102; left: 0px; position: relative;
                            top: 43px; border-right: gray thin solid; border-top: gray thin solid; border-left: gray thin solid;
                            border-bottom: gray thin solid; font-size: 12px; overflow: hidden; clip: rect(auto auto auto auto);"
                            Width="342px" AllowPaging="True" AllowSorting="True" Font-Size="Small" AutoGenerateColumns="False"
                            CellSpacing="2" HorizontalAlign="Left" BorderColor="LightGray" BorderStyle="None"
                            PageSize="14" OnSorting="GridView1_Sorting" OnRowCommand="GridView1_RowCommand"
                            EmptyDataText="No records found" ShowFooter="True">
                            <Columns>
                                <asp:CommandField HeaderText="Detail" ShowSelectButton="True" FooterText="Select">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Center" Width="10px" />
                                </asp:CommandField>
                                <asp:BoundField DataField="equipmentID" HeaderText="Equipment ID" SortExpression="equipmentID">
                                    <ItemStyle HorizontalAlign="Left" Width="60px" />
                                    <HeaderStyle HorizontalAlign="Center" />
                                </asp:BoundField>
                                <asp:BoundField DataField="equipmentname" HeaderText="Equipment Name" FooterText="Total">
                                    <HeaderStyle HorizontalAlign="Center" />
                                    <ItemStyle HorizontalAlign="Left" Width="240px" />
                                    <FooterStyle HorizontalAlign="Right" />
                                </asp:BoundField>
                                <asp:BoundField DataField="hours" HeaderText="Hours" NullDisplayText="0">
                                    <ItemStyle HorizontalAlign="Right" Width="80px" />
                                    <FooterStyle HorizontalAlign="Right" />
                                </asp:BoundField>
                            </Columns>
                            <HeaderStyle BackColor="#FFC080" Height="35px" />
                            <AlternatingRowStyle BackColor="#FFFFC0" />
                            <SelectedRowStyle BackColor="#FF8080" />
                            <EditRowStyle BackColor="#FF8080" />
                            <RowStyle Height="20px" />
                            <FooterStyle BackColor="#FF8080" />
                        </asp:GridView>
    Code Behind:


    Code:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
    
            Dim tabledata As Data.DataRowView = e.Row.DataItem
    
            If e.Row.RowType = DataControlRowType.Footer Then
                e.Row.Cells(0).Text = "Select"
                e.Row.Cells(2).Text = "Selection Total"
                e.Row.Cells(3).Text = Session("TotalHours")
            End If
    
        End Sub

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: GridView Footer - need help

    Hello,

    I am not sure that I follow? What exactly isn't working for you? Or what is it you are trying to do, I think I must have missed something.

    Gary

  3. #3

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: GridView Footer - need help

    OK, I would like to have a select button on the footer row (like I now have on the data rows). The current select button on the data rows calls a stored procedure showing additional details in a new grid view.


    Code:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
    
            Dim tabledata As Data.DataRowView = e.Row.DataItem
    
            If e.Row.RowType = DataControlRowType.Footer Then
                e.Row.Cells(0).Text = "Select"
                e.Row.Cells(0).Attributes.Add ---> onclick ?         
                e.Row.Cells(2).Text = "Selection Total"
                e.Row.Cells(3).Text = Session("TotalHours")
            End If
    
        End Sub
    Code:
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
    
            If e.CommandName = "Select" Then
    
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                Dim mySelectedRow As GridViewRow = GridView1.Rows(index)
                Dim mySelectedCell As TableCell
    
                mySelectedCell = mySelectedRow.Cells(1)
                Equipment_ID = mySelectedCell.Text.ToString
    
                GetItemDetail(Equipment_ID)
                DisplayItemDetail()
    
            End If
    
        End Sub
    Last edited by snufse; May 21st, 2009 at 07:22 AM.

  4. #4

    Thread Starter
    Fanatic Member snufse's Avatar
    Join Date
    Jul 2004
    Location
    Jupiter, FL
    Posts
    912

    Re: GridView Footer - need help

    I managed to add a link button to my gridview footer like this:


    Code:
    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
    
            Dim tabledata As Data.DataRowView = e.Row.DataItem
    
            If e.Row.RowType = DataControlRowType.Footer Then
                myLinkButton.Text = "Select"
                myLinkButton.CommandName = "SelectFooter"
                AddHandler myLinkButton.Click, New EventHandler(AddressOf ClickHandler)
                e.Row.Cells(0).Controls.Add(myLinkButton)
                e.Row.Cells(2).Text = "Selection Total"
                e.Row.Cells(3).Text = Session("TotalHours")
            End If
    
        End Sub
    Now my next question is how do I capture the "click" event? I tried this but does not work:

    Code:
    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
    
            If e.CommandName = "Select" Then
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                Dim mySelectedRow As GridViewRow = GridView1.Rows(index)
                Dim mySelectedCell As TableCell
    
                mySelectedCell = mySelectedRow.Cells(1)
                Equipment_ID = mySelectedCell.Text.ToString
    
                GetItemDetail(Equipment_ID)
                DisplayItemDetail()
            End If
    
            If e.CommandName = "SelectFooter" Then
                AddHandler myLinkButton.Click, New EventHandler(AddressOf ClickHandler)
            End If
    
    End Sub
    Code:
    Public Sub ClickHandler(ByVal sender As Object, ByVal e As EventArgs)
    
            'Handle LinkButton click event here. But this event never gets called...
    
    End Sub
    Last edited by snufse; May 21st, 2009 at 09:14 AM.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: GridView Footer - need help

    Couldn't you add the link straight to the Footer's template?

    Also, where is myLinkButton defined? Is there a reason it's not being defined in the DataBound event?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width