Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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
  #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.

  #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

  #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
  #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
  #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


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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.