ASP.net query......

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vebuda
    New Member
    • Jun 2007
    • 8

    ASP.net query......

    Hi all,

    I am using gridview in asp.net. I am binding a datasource to gird view in pageload event.I want to refresh the gridview on click of a check box so that data related to that checkbox only is displayed. How can i achieve this? Is it possible to change the data depending on a condition in a gridview once it is databound?Any help is appreciated I am blocked on this.
    Last edited by jhardman; Apr 9 '08, 11:18 PM. Reason: moved to .Net forum. ASP forum is for "classic" ASP
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi vebuda,

    Firstly, this is the Classic ASP forum and as your question is related to ASP.NET it should really go in the .NET forum.

    But to answer your question; if you want to change the appearance of a GridView then I'd do so as the items are databound.

    In the scenario you describe above you can re-bind the GridView on the click of a checkbox (or some other control if desired) then in the OnItemDataBound Sub you can do something like the following:
    Code:
    Dim check As CheckBox = e.Item.FindControl("Check1") 
     
    If Not check.Checked Then
    e.Item.Visible = False
    End If
    so in this instance I'd hide every row where the checkbox wasn't checked.

    Hope this helps,

    Dr B

    Comment

    • shweta123
      Recognized Expert Contributor
      • Nov 2006
      • 692

      #3
      Hi,

      You can do it this way :

      Public sub BindTOGrid()
      Dim sql as String

      Dim ds as Dataset
      Dim da As OleDbDataAdapte r
      Dim comm as OleDbCommand
      Dim con as new OleDbConnection
      Dim chkValue

      chkValue = CheckBox1.Text

      '''Fire your sql query here
      sql = "Select * from tablename where columnName =" & chkValue & ""

      con.ConnectionS tring = "...."
      con.open


      da= new oldebDataAdapte r(Sql,con)

      da.Fill(ds)

      ''''Bind data to gridview

      GridView1.DataS ource = ds.Tables(0)
      GridView1.DataB ind()

      con.close
      End Sub




      Originally posted by vebuda
      Hi all,

      I am using gridview in asp.net. I am binding a datasource to gird view in pageload event.I want to refresh the gridview on click of a check box so that data related to that checkbox only is displayed. How can i achieve this? Is it possible to change the data depending on a condition in a gridview once it is databound?Any help is appreciated I am blocked on this.

      Comment

      • shweta123
        Recognized Expert Contributor
        • Nov 2006
        • 692

        #4
        Hi,

        You can do it this way:

        Code:
        Public sub BindTOGrid()
        Dim sql as String 
        
        Dim ds as Dataset
        Dim da As OleDbDataAdapter 
        Dim comm as OleDbCommand
        Dim con as new OleDbConnection
        Dim chkValue
        
        chkValue = CheckBox1.Text 
        
        '''Fire your sql query here
        sql = "Select * from tablename where columnName =" & chkValue & "" 
        
        con.ConnectionString = "...."
        con.open
        
        
        da= new oldebDataAdapter(Sql,con)
        
        da.Fill(ds)
        
        ''''Bind data to gridview
        
        GridView1.DataSource = ds.Tables(0)
        GridView1.DataBind()
        
        con.close
        End Sub

        Comment

        Working...