How to insert value in dropdownlist in the footer row of gridview?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • coolnavjot31
    New Member
    • Jan 2010
    • 2

    How to insert value in dropdownlist in the footer row of gridview?

    I have Gridview with Template Field.And I Put Dropdownlist at footer row of gridview. but when i insert the value from a database table in dropdownlist , than it generate error.
    for filling value ,

    i declare variable like in databound event of gridview.
    for example:

    dim varclass as new dropdownlist
    varclass=Gridvi ew1.footerRow.f indcontrol("ddl Class")

    it generate error that: Object reference not set to an instance of an object.
    So any one have Answer??
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    You should be checking to make sure that the row being bound is the Footer and not a Header or Data row. If you try to access a variable in the footer row when it isn't the footer row that is being bound then you'll have a problem.

    For example:
    Code:
    Private Sub myGridView_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles myGridView.RowDataBound
    
      Select Case e.Row.RowType
        Case DataControlRowType.Header
          'In this case the header row is being bound 
          'All controls in the header row are accessible
        Case DataControlRowType.DataRow
          'In this case a Data Row is being bound
          'All controls in the data row are accessible
        Case DataControlRowType.Footer
          'In this case the footer row is being bound
          'All controls in the footer row are now accessible
        Case DataControlRowType.Pager
          'In this case the pager row is being bound
          'All controls in the pager row are accessible
    '....
      End Select
    
    End Sub
    The controls available to you all depends on which row is currently being bound. If the row being bound is a data row, then obviously you wont find controls that are in the footer row.

    When you use the findControl method you should always make sure that the control was found before you try to use it (check to make sure that the control IsNot Nothing before you try to use it)

    -Frinny

    Comment

    Working...