473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 :
Expand|Select|Wrap|Line Numbers
  1.     Protected Sub btngo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btngo.Click
  2.  
  3.         Dim dt As Data.DataTable
  4.         Dim query As String
  5.  
  6.         query = "SELECT vehicleregNo FROM [montrealTransactions]WHERE MONTH(RentedOn) = '" _
  7.         & ddlmonth.SelectedValue & "'  AND year(RentedOn) = '" & ddlyear.SelectedValue & "'"
  8.  
  9.         dt = DB.QuerySelect(query)
  10.         If dt.Rows.Count > 0 Then
  11.             With dt.Rows(0)
  12.                 Dim d As String = .Item("vehicleregNo")
  13.                 txtNo.Text = (d)
  14.             End With
  15.             Exit Sub
  16.         End If
  17.     End Sub
insted of returning it in a text box i want a gridview .. So could you help me please ?

thanx alot :)
Aug 17 '09 #1

✓ answered by Frinavale

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:

Expand|Select|Wrap|Line Numbers
  1. Private gridViewDataSource As Data.DataView
  2.  
  3.  Protected Sub btngo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btngo.Click
  4.  
  5.         Dim dt As Data.DataTable
  6.         Dim query As String
  7.  
  8.         query = "SELECT vehicleregNo FROM [montrealTransactions]WHERE MONTH(RentedOn) = '" _
  9.         & ddlmonth.SelectedValue & "'  AND year(RentedOn) = '" & ddlyear.SelectedValue & "'"
  10.  
  11.         dt = DB.QuerySelect(query)
  12.         If dt.Rows.Count > 0 Then
  13.           gridViewDataSource = new Data.DataView(dt)
  14.           theGridView.DataSource = gridViewDataSource
  15.           theGridView.DataBind()
  16.         End If
  17.     End Sub
I'm almost certain that the source I linked you to in my previous reply would have covered this :)

-Frinny

4 2353
Frinavale
9,735 Expert Mod 8TB
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....there 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.
Aug 17 '09 #2
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" ??
Aug 18 '09 #3
Frinavale
9,735 Expert Mod 8TB
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:

Expand|Select|Wrap|Line Numbers
  1. Private gridViewDataSource As Data.DataView
  2.  
  3.  Protected Sub btngo_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btngo.Click
  4.  
  5.         Dim dt As Data.DataTable
  6.         Dim query As String
  7.  
  8.         query = "SELECT vehicleregNo FROM [montrealTransactions]WHERE MONTH(RentedOn) = '" _
  9.         & ddlmonth.SelectedValue & "'  AND year(RentedOn) = '" & ddlyear.SelectedValue & "'"
  10.  
  11.         dt = DB.QuerySelect(query)
  12.         If dt.Rows.Count > 0 Then
  13.           gridViewDataSource = new Data.DataView(dt)
  14.           theGridView.DataSource = gridViewDataSource
  15.           theGridView.DataBind()
  16.         End If
  17.     End Sub
I'm almost certain that the source I linked you to in my previous reply would have covered this :)

-Frinny
Aug 18 '09 #4
I am realy thankful bro.

wish u all the best :)
Aug 19 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
4
by: Larry Grady | last post by:
Anyone up for a challenge? I've been struggling with this for a few days and was hoping someone could help me. Pouring through all the messageboards I just can't find the solution. We have a...
0
by: Bob Keller | last post by:
I've been working on a web project (VB) previously done with DataGrids in VS2003. I've migrated the project over to VS2005, because I like what I've seen of the newer features. Soooo.. I've...
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: MarkAurit | last post by:
I have a gridview that some boundfield and buttonfield controls. I have a data element I 1. want to use when the button is clicked for a given row, but 2. dont want it visibly displayed in the...
5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
0
by: loga123 | last post by:
Hi All, I am using asp.net 2.0. I have a gridview with AutoGenerateEditButton="True" . I am trying to access newValues in rowupdating event. It gives me "oldvalues" collection. I have a)...
3
by: Mike | last post by:
I'm using the 2.0 framework and cannot get a gridview to return records with an objectDataSource. I can preview the data from the datatable. To make this as simple as possible I used the wizard...
6
by: rcoco | last post by:
Hi, I have a datagrid that is ment to insert data. But when I run the form only the header appears. I would like some advise from you all and solve this problem I'm using visual studio 2003. My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.