p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ASP.NET 2.0 Professional (http://p2p.wrox.com/forumdisplay.php?f=215)
-   -   How to display data into Grid View? (http://p2p.wrox.com/showthread.php?t=55455)

Somesh March 16th, 2007 02:15 AM

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

JoinTTT March 16th, 2007 07:29 PM

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.


nesrine March 18th, 2007 01:51 AM

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


DarkForce May 23rd, 2007 02:01 AM

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

DarkForce May 23rd, 2007 02:38 AM

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

pavank May 25th, 2007 07:07 AM

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


All times are GMT -4. The time now is 08:59 PM.

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