Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add dropdownlist in the footer section 1

Status
Not open for further replies.

taree

Technical User
May 31, 2008
316
US
Is it possible to add a dropdownlist in the footer section of gridview? If so, can someone show me how I can do this.I just want to use the dropdownlist for the users to select the number of rows per page.

thank you
 
I think I got it. thank you. I am going to create a template field like this.

Code:
  <asp:TemplateField>
            <FooterTemplate>
                 <asp:DropDownList ID="ddlDropDownList" runat ="server" >
                </asp:DropDownList>
            </FooterTemplate>
      </asp:TemplateField>
 
Thank you for the response. that is what i am doing but the problem is how i can insert dropdownlist in the cell 0
Code:
 If (e.Row.RowType = DataControlRowType.Footer) Then
            e.Row.Cells(0).ColumnSpan = 10
            e.Row.Cells.RemoveAt(9)
            e.Row.Cells.RemoveAt(8)
            e.Row.Cells.RemoveAt(7)
            e.Row.Cells.RemoveAt(6)
            e.Row.Cells.RemoveAt(5)
            e.Row.Cells.RemoveAt(4)
            e.Row.Cells.RemoveAt(3)
            e.Row.Cells.RemoveAt(2)
            e.Row.Cells.RemoveAt(1)
            e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(0).Text = "Show Rows :"
            
        End If
 
You only need to add it from code like I showed if you are adding it dynamically (which is what I understood your question to mean). If you are adding it at design time like in your second post then you don't need to add it as it already exists.

Mark,

Darlington Web Design[tab]|[tab]Experts, Information, Ideas & Knowledge[tab]|[tab]ASP.NET Tips & Tricks
 
Thank you again for the response. yes, my peference it to do it from codebehind like this. I know this is not right but this is what I would like to do

Code:
    Dim ddlRows As DropDownList = New DropDownList
            ddlRows.Items.Insert(1, New ListItem("20", "20"))
            ddlRows.Items.Insert(2, New ListItem("30", "30"))
            ddlRows.Items.Insert(3, New ListItem("40", "40"))
            ddlRows.Items.Insert(4, New ListItem("50", "50"))

            e.Row.Cells(0).Text = ddlRows.ToString
 
Almost there with a one queston. I would like to to have
"show Rows" text infront of the dropdownlist. I tried like below and the text still now show up. Am I missing something here.

Code:
  If (e.Row.RowType = DataControlRowType.Footer) Then
            e.Row.Cells(0).ColumnSpan = 9
            e.Row.Cells.RemoveAt(9)
            e.Row.Cells.RemoveAt(8)
            e.Row.Cells.RemoveAt(7)
            e.Row.Cells.RemoveAt(6)
            e.Row.Cells.RemoveAt(5)
            e.Row.Cells.RemoveAt(4)
            e.Row.Cells.RemoveAt(3)
            e.Row.Cells.RemoveAt(2)

            Dim ddlRows As DropDownList = New DropDownList()
            ddlRows.Items.Insert(0, New ListItem("20", "20"))
            ddlRows.Items.Insert(1, New ListItem("30", "30"))
            ddlRows.Items.Insert(2, New ListItem("40", "40"))
            ddlRows.Items.Insert(3, New ListItem("50", "50"))
            ddlRows.AutoPostBack = True
            ddlRows.Width = 50
            e.Row.Cells(1).Text = "Show Rows :"
            e.Row.Cells(1).HorizontalAlign = HorizontalAlign.Right
            e.Row.Cells(1).Controls.Add(ddlRows)


            e.Row.Cells(0).Text = "Page " & (gvVendorSearch.PageIndex + 1) & " of " & gvVendorSearch.PageCount
        End If
 
It worked. Thank you so much for your time and help.
 
My other question is how can I change the rows per page in the gridview when the dropdownlist selection change.

Code:
  If (e.Row.RowType = DataControlRowType.Footer) Then
            e.Row.Cells(0).ColumnSpan = 10
            e.Row.Cells.RemoveAt(9)
            e.Row.Cells.RemoveAt(8)
            e.Row.Cells.RemoveAt(7)
            e.Row.Cells.RemoveAt(6)
            e.Row.Cells.RemoveAt(5)
            e.Row.Cells.RemoveAt(4)
            e.Row.Cells.RemoveAt(3)
            e.Row.Cells.RemoveAt(2)
            e.Row.Cells.RemoveAt(1)


            Dim ddlPageSize As New DropDownList()
            ddlPageSize.ID = "PageSize"
            ddlPageSize.AutoPostBack = True
            ddlPageSize.Items.Add(New ListItem("10", "10"))
            ddlPageSize.Items.Add(New ListItem("20", "25"))
            ddlPageSize.Items.Add(New ListItem("30", "50"))
            ddlPageSize.Items.Add(New ListItem("40", "100"))
            ddlPageSize.Items.Add(New ListItem("All", (Me.gvVendorSearch.PageCount * Me.gvVendorSearch.PageSize).ToString()))
            ddlPageSize.AutoPostBack = True
            ddlPageSize.Width = Unit.Percentage(5)

            ' ddlPageSize.SelectedIndexChanged += New EventHandler(AddressOf ddlPageSize_SelectedIndexChanged)

            Dim lblShowRow As Label = New Label
            Dim lblSpaceHolder As Label = New Label
            Dim lblDisTxtFirst As Label = New Label
            Dim lblDisTxtLast As Label = New Label
            lblDisTxtFirst.Text = "Show "
            lblDisTxtLast.Text = " Records Per Page "
            lblSpaceHolder.Width = Unit.Percentage(72)
            lblShowRow.Text = "Page " & (gvVendorSearch.PageIndex + 1) & " of " & gvVendorSearch.PageCount



            e.Row.Cells(0).HorizontalAlign = HorizontalAlign.Left
            e.Row.Cells(0).Controls.Add(lblShowRow)
            e.Row.Cells(0).Controls.Add(lblSpaceHolder)
            e.Row.Cells(0).Controls.Add(lblDisTxtFirst)
            e.Row.Cells(0).Controls.Add(ddlPageSize)
            e.Row.Cells(0).Controls.Add(lblDisTxtLast)


        End If
 
Got it. I think I was too quick to post it here before I give it a thought :). thank you !!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top