returning data into gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • csgirl87
    New Member
    • Aug 2009
    • 3

    returning data into gridview

    I am new to asp.net

    i am using it with vb.net language

    i had do the code .. and it is returning the result in a textbox right now

    cause i don't know how to returned it in a gridview ..

    i tired to read and follow but i could not ..

    i had a ready function named (QuerySelect) for the connection with the server .. now i use it like that :
    Code:
        Protected Sub btngo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btngo.Click
    
            Dim dt As Data.DataTable
            Dim query As String
    
            query = "SELECT vehicleregNo FROM [montrealTransactions]WHERE MONTH(RentedOn) = '" _
            & ddlmonth.SelectedValue & "'  AND year(RentedOn) = '" & ddlyear.SelectedValue & "'"
    
            dt = DB.QuerySelect(query)
            If dt.Rows.Count > 0 Then
                With dt.Rows(0)
                    Dim d As String = .Item("vehicleregNo")
                    txtNo.Text = (d)
                End With
                Exit Sub
            End If
        End Sub
    insted of returning it in a text box i want a gridview .. So could you help me please ?

    thanx alot :)
    Last edited by Frinavale; Aug 17 '09, 10:53 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    All the information you need on GridViews and any other .NET controls can be found in the MSDN Library. This resource should get you pointed in the right direction....th ere are multiple articles on the GridView there. I recommend bookmarking the MSDN Library and using it as your primary resource when developing in .NET.

    Please take the time to research the problem before you post your question. The experts here are more than willing to help you with a specific problem but you have to do your part to learn the basics. Please take the time to read over the posting guidelines specifically the section on Before you post your question.

    Comment

    • csgirl87
      New Member
      • Aug 2009
      • 3

      #3
      execuse me bro.

      i know all what you had post here ..

      i know how to bind a sql with gridview

      but my problem is diffrent .. i had not have an sql connection in my form ..

      there is one main connection with the company server in the whole project ..

      and there is a function that we can use to return data from the database ..

      i dont know now how to returned it into gridview insted of " text box" ??

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Sorry for the generic response but you didn't make it clear as to what the problem was.

        Anyways, it's not as hard as you're making it out to be. Instead of looping through the table and printing each row in a TextBox, use that table as the DataSource for the GridView. Once you've assigned this data source be sure to call the GridView's DataBind() method. This will bind the data to the GridView.

        I like to use a DataView instead of a Table because DataViews have paging capabilities which makes life a little easier when doing custom GridView paging.

        I would do something like:

        Code:
        Private gridViewDataSource As Data.DataView
        
         Protected Sub btngo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btngo.Click
         
                Dim dt As Data.DataTable
                Dim query As String
         
                query = "SELECT vehicleregNo FROM [montrealTransactions]WHERE MONTH(RentedOn) = '" _
                & ddlmonth.SelectedValue & "'  AND year(RentedOn) = '" & ddlyear.SelectedValue & "'"
         
                dt = DB.QuerySelect(query)
                If dt.Rows.Count > 0 Then
                  gridViewDataSource = new Data.DataView(dt)
                  theGridView.DataSource = gridViewDataSource
                  theGridView.DataBind()
                End If
            End Sub
        I'm almost certain that the source I linked you to in my previous reply would have covered this :)

        -Frinny

        Comment

        • csgirl87
          New Member
          • Aug 2009
          • 3

          #5
          I am realy thankful bro.

          wish u all the best :)

          Comment

          Working...