Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old March 16th, 2007, 02:15 AM
Authorized User
 
Join Date: Nov 2006
Location: Bangalore, Karnataka, India.
Posts: 47
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Somesh
Default How to display data into Grid View?

Hi
All;

I need to display the data (Fetched from data base table by SQL query) into a grid view.

I have no option to bind the grid view to the database.


So, how can I do this?

Any suggestion will be gladly accepted.

With Regards

Somesh


someshchaterjee
__________________
somesh chaterjee
Reply With Quote
  #2 (permalink)  
Old March 16th, 2007, 07:29 PM
Authorized User
 
Join Date: Mar 2007
Location: , , .
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to JoinTTT
Default

Hi,
What do you mean with your saying, 'I have no option to bind gridview to the database'??

I know two choices for binding data to gridview!

First, You can use sqldatasource sqldatasource.
Second, You can bind data in code behind without using sqldatasource control.

Please Focus on them.

Reply With Quote
  #3 (permalink)  
Old March 18th, 2007, 01:51 AM
Authorized User
 
Join Date: Feb 2007
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What about the following, this is answering you question, cheers

 Dim ds As New Data.DataSet
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim con As New SqlClient.SqlConnection("data source=Nesrine;initial catalog=ASPNETDB;integrated security=true")

        Dim da As New SqlClient.SqlDataAdapter("select ContactId,Title,EmailAddress,FirstName,LastName from Person.Contact", con)

        da.Fill(ds)
        Me.DataGridView1.DataSource = ds.Tables(0)


    End Sub

Reply With Quote
  #4 (permalink)  
Old May 23rd, 2007, 02:01 AM
Authorized User
 
Join Date: May 2007
Location: Frankfurt, Germany, Germany.
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to DarkForce
Default

1.put the sqldatsascource into your contentplaceholder
2. use the sqldatascource wizard to configure your *.mdb database
3.put the grid view next to your sqldatascource
4.use the gridview wizard to select your sqldatascoure

p.s
by configuring the sqldatascource you can set up a sql query

So long
Reply With Quote
  #5 (permalink)  
Old May 23rd, 2007, 02:38 AM
Authorized User
 
Join Date: May 2007
Location: Frankfurt, Germany, Germany.
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to DarkForce
Default

I have also a question concerining sqldatascources using a button to change the datascource by click.
Does someone know the c# code for setting up a new sqldatascource by clicking a button?

So long
Reply With Quote
  #6 (permalink)  
Old May 25th, 2007, 07:07 AM
Registered User
 
Join Date: May 2007
Location: guntur, ap, India.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to pavank
Default

Take one function like

private void fillgrid()
{
     here take sqlconnection

   and using sqldataadapter or sqlcommand select query for filling in girdview

 like
    sqldataadapter sqlda=new sqldataadapter(sqlquery,con);
 or
     sqlcommand sqlcmd=new sqlcommand(sqlquery,con);

   for sqldataadapter take dataset

  as dataset ds=new dataset();

    and fill sqldataadapter with dataset for getting data like

 da.fill(ds);

 and write

 gridview1.datasource=ds; // gridview1 is id of gridview.
 gridview1.databind();

}

you call this function in page_load...

like

 if(!ispostback)
   fillgrid();

use this one .....

gud luck
bye










}

pavan
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Paging Data grid view Prakash001 Visual Basic 2005 Basics 0 February 6th, 2008 03:07 AM
Deleting multiple rows in data view or grid deepakbachelor SQL Server 2005 1 December 7th, 2007 01:19 PM
custome display in grid view MunishBhatia ASP.NET 2.0 Professional 5 November 16th, 2007 10:45 PM
Data Grid View CoolDude C# 2005 3 March 10th, 2007 04:37 AM



All times are GMT -4. The time now is 02:50 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.