473,486 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datagrid and datareader

Hi,

I have 2 more questions :

1. Can I fill a datagrid by using a DataReader or does it have to be a
DataSet or a DataView?

2. In my datagrid I need to display two images and one of does images has te
be a link to a new page. How would you do that ?

Thanks.
Nov 18 '05 #1
7 1792

1:) You can use a datareader to fill a datalist/datagrid.

Dim Conn As New System.Data.SqlClient.SqlConnection
Conn.ConnectionString = "Server=YourServer;
Database=Northwind;Trusted_Connection=True;"

Conn.Open()

Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Employees", Conn)
Me.DataGrid2.DataSource = cmd.ExecuteReader
Me.DataGrid2.DataBind()

Conn.Close()

2:)
If no one else answers your question, before I get home from work I will
throw together an example for you. Is your e-mail address valid?

Jared

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have 2 more questions :

1. Can I fill a datagrid by using a DataReader or does it have to be a
DataSet or a DataView?

2. In my datagrid I need to display two images and one of does images has
te
be a link to a new page. How would you do that ?

Thanks.

Nov 18 '05 #2
Jared,

thx for the answer.
My email is a valid address BS********@hotmail.com
So there's no problem in sending me a reply there.

Thx.
Bart

"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...

1:) You can use a datareader to fill a datalist/datagrid.

Dim Conn As New System.Data.SqlClient.SqlConnection
Conn.ConnectionString = "Server=YourServer;
Database=Northwind;Trusted_Connection=True;"

Conn.Open()

Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Employees", Conn)
Me.DataGrid2.DataSource = cmd.ExecuteReader
Me.DataGrid2.DataBind()

Conn.Close()

2:)
If no one else answers your question, before I get home from work I will
throw together an example for you. Is your e-mail address valid?

Jared

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have 2 more questions :

1. Can I fill a datagrid by using a DataReader or does it have to be a
DataSet or a DataView?

2. In my datagrid I need to display two images and one of does images has te
be a link to a new page. How would you do that ?

Thanks.


Nov 18 '05 #3
This is a very good article with extra datagrid info:

http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:Om*************@TK2MSFTNGP12.phx.gbl...
Jared,

thx for the answer.
My email is a valid address BS********@hotmail.com
So there's no problem in sending me a reply there.

Thx.
Bart

"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...

1:) You can use a datareader to fill a datalist/datagrid.

Dim Conn As New System.Data.SqlClient.SqlConnection
Conn.ConnectionString = "Server=YourServer;
Database=Northwind;Trusted_Connection=True;"

Conn.Open()

Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Employees", Conn)
Me.DataGrid2.DataSource = cmd.ExecuteReader
Me.DataGrid2.DataBind()

Conn.Close()

2:)
If no one else answers your question, before I get home from work I will
throw together an example for you. Is your e-mail address valid?

Jared

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi,

I have 2 more questions :

1. Can I fill a datagrid by using a DataReader or does it have to be a
DataSet or a DataView?

2. In my datagrid I need to display two images and one of does images has te
be a link to a new page. How would you do that ?

Thanks.



Nov 18 '05 #4
Thx for the info
but i can't find the section where they explain how to display images in the
grid.
Nor can i find the section where they tell me how to display an image that
serves as a link for a new page.

"Nick" <Ni**@NTWorks.no.spam.fsnet.co.uk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
This is a very good article with extra datagrid info:

http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:Om*************@TK2MSFTNGP12.phx.gbl...
Jared,

thx for the answer.
My email is a valid address BS********@hotmail.com
So there's no problem in sending me a reply there.

Thx.
Bart

"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...

1:) You can use a datareader to fill a datalist/datagrid.

Dim Conn As New System.Data.SqlClient.SqlConnection
Conn.ConnectionString = "Server=YourServer;
Database=Northwind;Trusted_Connection=True;"

Conn.Open()

Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Employees", Conn) Me.DataGrid2.DataSource = cmd.ExecuteReader
Me.DataGrid2.DataBind()

Conn.Close()

2:)
If no one else answers your question, before I get home from work I will throw together an example for you. Is your e-mail address valid?

Jared

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
> Hi,
>
> I have 2 more questions :
>
> 1. Can I fill a datagrid by using a DataReader or does it have to be a > DataSet or a DataView?
>
> 2. In my datagrid I need to display two images and one of does
images has
> te
> be a link to a new page. How would you do that ?
>
> Thanks.
>
>



Nov 18 '05 #5
Part 5 - Template Columns.

Then in the code for the ItemDataBound event you add the HTML for the image.
If you want the image to be a link as well, then add the <A> tags. Eg:

Sub AddImage(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <>
ListItemType.Footer Then
e.Item.Cells(4).Text() = "<img src='../images/picture.gif'></img>"
End If
End Sub

Don't forget you need to add a template column to the datagrid, and set the
OnItemDataBound="AddImage" property for the datagrid.
(For the above code, the template column would need to be the 4th column)

<Columns>
<asp:BoundColumn......></asp:BoundColumn>
<asp:BoundColumn......></asp:BoundColumn>
<asp:BoundColumn......></asp:BoundColumn>
<asp:TemplateColumn HeaderText="No.">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
Nick
"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:eN****************@TK2MSFTNGP09.phx.gbl...
Thx for the info
but i can't find the section where they explain how to display images in the grid.
Nor can i find the section where they tell me how to display an image that
serves as a link for a new page.

"Nick" <Ni**@NTWorks.no.spam.fsnet.co.uk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
This is a very good article with extra datagrid info:

http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:Om*************@TK2MSFTNGP12.phx.gbl...
Jared,

thx for the answer.
My email is a valid address BS********@hotmail.com
So there's no problem in sending me a reply there.

Thx.
Bart

"Jared" <VB***********@email.com> wrote in message
news:10*************@corp.supernews.com...
>
> 1:) You can use a datareader to fill a datalist/datagrid.
>
> Dim Conn As New System.Data.SqlClient.SqlConnection
> Conn.ConnectionString = "Server=YourServer;
> Database=Northwind;Trusted_Connection=True;"
>
> Conn.Open()
>
> Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Employees", Conn) > Me.DataGrid2.DataSource = cmd.ExecuteReader
> Me.DataGrid2.DataBind()
>
> Conn.Close()
>
> 2:)
> If no one else answers your question, before I get home from work I will > throw together an example for you. Is your e-mail address valid?
>
> Jared
>
> "Bart Schelkens" <BS********@hotmail.com> wrote in message
> news:%2****************@TK2MSFTNGP09.phx.gbl...
> > Hi,
> >
> > I have 2 more questions :
> >
> > 1. Can I fill a datagrid by using a DataReader or does it have to
be
a > > DataSet or a DataView?
> >
> > 2. In my datagrid I need to display two images and one of does images has
> > te
> > be a link to a new page. How would you do that ?
> >
> > Thanks.
> >
> >
>
>



Nov 18 '05 #6
thx Nick,

I must have looked over it.

"Nick" <Ni**@NTWorks.no.spam.fsnet.co.uk> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Part 5 - Template Columns.

Then in the code for the ItemDataBound event you add the HTML for the image. If you want the image to be a link as well, then add the <A> tags. Eg:

Sub AddImage(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <>
ListItemType.Footer Then
e.Item.Cells(4).Text() = "<img src='../images/picture.gif'></img>"
End If
End Sub

Don't forget you need to add a template column to the datagrid, and set the OnItemDataBound="AddImage" property for the datagrid.
(For the above code, the template column would need to be the 4th column)

<Columns>
<asp:BoundColumn......></asp:BoundColumn>
<asp:BoundColumn......></asp:BoundColumn>
<asp:BoundColumn......></asp:BoundColumn>
<asp:TemplateColumn HeaderText="No.">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
Nick
"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:eN****************@TK2MSFTNGP09.phx.gbl...
Thx for the info
but i can't find the section where they explain how to display images in the
grid.
Nor can i find the section where they tell me how to display an image that serves as a link for a new page.

"Nick" <Ni**@NTWorks.no.spam.fsnet.co.uk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
This is a very good article with extra datagrid info:

http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:Om*************@TK2MSFTNGP12.phx.gbl...
> Jared,
>
> thx for the answer.
> My email is a valid address BS********@hotmail.com
> So there's no problem in sending me a reply there.
>
> Thx.
> Bart
>
> "Jared" <VB***********@email.com> wrote in message
> news:10*************@corp.supernews.com...
> >
> > 1:) You can use a datareader to fill a datalist/datagrid.
> >
> > Dim Conn As New System.Data.SqlClient.SqlConnection
> > Conn.ConnectionString = "Server=YourServer;
> > Database=Northwind;Trusted_Connection=True;"
> >
> > Conn.Open()
> >
> > Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Employees",

Conn)
> > Me.DataGrid2.DataSource = cmd.ExecuteReader
> > Me.DataGrid2.DataBind()
> >
> > Conn.Close()
> >
> > 2:)
> > If no one else answers your question, before I get home from work
I will
> > throw together an example for you. Is your e-mail address valid?
> >
> > Jared
> >
> > "Bart Schelkens" <BS********@hotmail.com> wrote in message
> > news:%2****************@TK2MSFTNGP09.phx.gbl...
> > > Hi,
> > >
> > > I have 2 more questions :
> > >
> > > 1. Can I fill a datagrid by using a DataReader or does it have

to be
a
> > > DataSet or a DataView?
> > >
> > > 2. In my datagrid I need to display two images and one of does

images
> has
> > > te
> > > be a link to a new page. How would you do that ?
> > >
> > > Thanks.
> > >
> > >
> >
> >
>
>



Nov 18 '05 #7
Nick

in the example I see that the image will always be the same.
I'm trying to find a way (but i'm not very successful) to make the name of
the file variable, because that name is stored in the datasource of my
datagrid.

Thx for any help

"Nick" <Ni**@NTWorks.no.spam.fsnet.co.uk> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Part 5 - Template Columns.

Then in the code for the ItemDataBound event you add the HTML for the image. If you want the image to be a link as well, then add the <A> tags. Eg:

Sub AddImage(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
If e.Item.ItemType <> ListItemType.Header And e.Item.ItemType <>
ListItemType.Footer Then
e.Item.Cells(4).Text() = "<img src='../images/picture.gif'></img>"
End If
End Sub

Don't forget you need to add a template column to the datagrid, and set the OnItemDataBound="AddImage" property for the datagrid.
(For the above code, the template column would need to be the 4th column)

<Columns>
<asp:BoundColumn......></asp:BoundColumn>
<asp:BoundColumn......></asp:BoundColumn>
<asp:BoundColumn......></asp:BoundColumn>
<asp:TemplateColumn HeaderText="No.">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
Nick
"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:eN****************@TK2MSFTNGP09.phx.gbl...
Thx for the info
but i can't find the section where they explain how to display images in the
grid.
Nor can i find the section where they tell me how to display an image that serves as a link for a new page.

"Nick" <Ni**@NTWorks.no.spam.fsnet.co.uk> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
This is a very good article with extra datagrid info:

http://aspnet.4guysfromrolla.com/articles/040502-1.aspx

"Bart Schelkens" <BS********@hotmail.com> wrote in message
news:Om*************@TK2MSFTNGP12.phx.gbl...
> Jared,
>
> thx for the answer.
> My email is a valid address BS********@hotmail.com
> So there's no problem in sending me a reply there.
>
> Thx.
> Bart
>
> "Jared" <VB***********@email.com> wrote in message
> news:10*************@corp.supernews.com...
> >
> > 1:) You can use a datareader to fill a datalist/datagrid.
> >
> > Dim Conn As New System.Data.SqlClient.SqlConnection
> > Conn.ConnectionString = "Server=YourServer;
> > Database=Northwind;Trusted_Connection=True;"
> >
> > Conn.Open()
> >
> > Dim cmd As New SqlClient.SqlCommand("SELECT * FROM Employees",

Conn)
> > Me.DataGrid2.DataSource = cmd.ExecuteReader
> > Me.DataGrid2.DataBind()
> >
> > Conn.Close()
> >
> > 2:)
> > If no one else answers your question, before I get home from work
I will
> > throw together an example for you. Is your e-mail address valid?
> >
> > Jared
> >
> > "Bart Schelkens" <BS********@hotmail.com> wrote in message
> > news:%2****************@TK2MSFTNGP09.phx.gbl...
> > > Hi,
> > >
> > > I have 2 more questions :
> > >
> > > 1. Can I fill a datagrid by using a DataReader or does it have

to be
a
> > > DataSet or a DataView?
> > >
> > > 2. In my datagrid I need to display two images and one of does

images
> has
> > > te
> > > be a link to a new page. How would you do that ?
> > >
> > > Thanks.
> > >
> > >
> >
> >
>
>



Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3250
by: Al | last post by:
in order to implement sorting, paging in a datagrid, can I have the datasource of the datagrid a datareader or it must be a dataset then I create a dataview and make it a datasource of the...
6
5053
by: Ricardo Luceac | last post by:
Hi... My program make a select to an table and return the results to a datagrid, it's all ok with dataset, but in large tables it needs to get the entire table to show in datagrid and sometimes...
5
5747
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
1
4376
by: Paul Hobbs | last post by:
Hi Everyone, I am trying to implement a DataGrid that uses Custom paging, but the DataSource is a SQLDataReader, not a DataSet. I have seen examples that use the Fill method of a DataAdapter to...
1
1545
by: BC | last post by:
Hi, Been searching the newgroups but haven't found an answer. I'm used to binding disconnected ADO recordsets to Datagrid controls and tweaking the Datagrid to suit my needs (columnheader,...
7
1775
by: Joe | last post by:
Hi, I’m new to asp.net. I want to create an asp.net page that allows user to edit the data. I have pasted my code below. I am able to display the data in a datagrid. At the bottom of the page...
7
14949
by: BobAchgill | last post by:
I am trying to decide which of these controls to use to implement letting my user select a full row from MyList. The MyList has several columns which would be nice to sort by at run time. The...
3
3332
by: tshad | last post by:
I am using VS 2003 and trying to build a standalone application. I have been writing all my asp.net work using DW and am just now trying to build a application that will read some of the tables I...
1
6508
by: MastaKay | last post by:
I hv dropdownlist on a c# page connected to a database(MS Access). I want to get values onto my datagrid when I select a value from the dropdownlist.The Item I select from the dropdown will...
0
6964
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
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7330
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...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.