473,799 Members | 3,161 Online
Bytes | Software Development & Data Engineering Community
+ 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 1816

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

Dim Conn As New System.Data.Sql Client.SqlConne ction
Conn.Connection String = "Server=YourSer ver;
Database=Northw ind;Trusted_Con nection=True;"

Conn.Open()

Dim cmd As New SqlClient.SqlCo mmand("SELECT * FROM Employees", Conn)
Me.DataGrid2.Da taSource = cmd.ExecuteRead er
Me.DataGrid2.Da taBind()

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********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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********@hotm ail.com
So there's no problem in sending me a reply there.

Thx.
Bart

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

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

Dim Conn As New System.Data.Sql Client.SqlConne ction
Conn.Connection String = "Server=YourSer ver;
Database=Northw ind;Trusted_Con nection=True;"

Conn.Open()

Dim cmd As New SqlClient.SqlCo mmand("SELECT * FROM Employees", Conn)
Me.DataGrid2.Da taSource = cmd.ExecuteRead er
Me.DataGrid2.Da taBind()

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********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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********@hot mail.com> wrote in message
news:Om******** *****@TK2MSFTNG P12.phx.gbl...
Jared,

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

Thx.
Bart

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

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

Dim Conn As New System.Data.Sql Client.SqlConne ction
Conn.Connection String = "Server=YourSer ver;
Database=Northw ind;Trusted_Con nection=True;"

Conn.Open()

Dim cmd As New SqlClient.SqlCo mmand("SELECT * FROM Employees", Conn)
Me.DataGrid2.Da taSource = cmd.ExecuteRead er
Me.DataGrid2.Da taBind()

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********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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.n o.spam.fsnet.co .uk> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
This is a very good article with extra datagrid info:

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

"Bart Schelkens" <BS********@hot mail.com> wrote in message
news:Om******** *****@TK2MSFTNG P12.phx.gbl...
Jared,

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

Thx.
Bart

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

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

Dim Conn As New System.Data.Sql Client.SqlConne ction
Conn.Connection String = "Server=YourSer ver;
Database=Northw ind;Trusted_Con nection=True;"

Conn.Open()

Dim cmd As New SqlClient.SqlCo mmand("SELECT * FROM Employees", Conn) Me.DataGrid2.Da taSource = cmd.ExecuteRead er
Me.DataGrid2.Da taBind()

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********@hot mail.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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 DataGridItemEve ntArgs)
If e.Item.ItemType <> ListItemType.He ader And e.Item.ItemType <>
ListItemType.Fo oter 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:BoundColum n......></asp:BoundColumn >
<asp:BoundColum n......></asp:BoundColumn >
<asp:BoundColum n......></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="No. ">
<ItemTemplate >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
Nick
"Bart Schelkens" <BS********@hot mail.com> wrote in message
news:eN******** ********@TK2MSF TNGP09.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.n o.spam.fsnet.co .uk> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
This is a very good article with extra datagrid info:

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

"Bart Schelkens" <BS********@hot mail.com> wrote in message
news:Om******** *****@TK2MSFTNG P12.phx.gbl...
Jared,

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

Thx.
Bart

"Jared" <VB***********@ email.com> wrote in message
news:10******** *****@corp.supe rnews.com...
>
> 1:) You can use a datareader to fill a datalist/datagrid.
>
> Dim Conn As New System.Data.Sql Client.SqlConne ction
> Conn.Connection String = "Server=YourSer ver;
> Database=Northw ind;Trusted_Con nection=True;"
>
> Conn.Open()
>
> Dim cmd As New SqlClient.SqlCo mmand("SELECT * FROM Employees", Conn) > Me.DataGrid2.Da taSource = cmd.ExecuteRead er
> Me.DataGrid2.Da taBind()
>
> 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********@hot mail.com> wrote in message
> news:%2******** ********@TK2MSF TNGP09.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.n o.spam.fsnet.co .uk> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
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 DataGridItemEve ntArgs)
If e.Item.ItemType <> ListItemType.He ader And e.Item.ItemType <>
ListItemType.Fo oter 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:BoundColum n......></asp:BoundColumn >
<asp:BoundColum n......></asp:BoundColumn >
<asp:BoundColum n......></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="No. ">
<ItemTemplate >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
Nick
"Bart Schelkens" <BS********@hot mail.com> wrote in message
news:eN******** ********@TK2MSF TNGP09.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.n o.spam.fsnet.co .uk> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
This is a very good article with extra datagrid info:

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

"Bart Schelkens" <BS********@hot mail.com> wrote in message
news:Om******** *****@TK2MSFTNG P12.phx.gbl...
> Jared,
>
> thx for the answer.
> My email is a valid address BS********@hotm ail.com
> So there's no problem in sending me a reply there.
>
> Thx.
> Bart
>
> "Jared" <VB***********@ email.com> wrote in message
> news:10******** *****@corp.supe rnews.com...
> >
> > 1:) You can use a datareader to fill a datalist/datagrid.
> >
> > Dim Conn As New System.Data.Sql Client.SqlConne ction
> > Conn.Connection String = "Server=YourSer ver;
> > Database=Northw ind;Trusted_Con nection=True;"
> >
> > Conn.Open()
> >
> > Dim cmd As New SqlClient.SqlCo mmand("SELECT * FROM Employees",

Conn)
> > Me.DataGrid2.Da taSource = cmd.ExecuteRead er
> > Me.DataGrid2.Da taBind()
> >
> > 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********@hot mail.com> wrote in message
> > news:%2******** ********@TK2MSF TNGP09.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.n o.spam.fsnet.co .uk> wrote in message
news:%2******** **********@TK2M SFTNGP12.phx.gb l...
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 DataGridItemEve ntArgs)
If e.Item.ItemType <> ListItemType.He ader And e.Item.ItemType <>
ListItemType.Fo oter 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:BoundColum n......></asp:BoundColumn >
<asp:BoundColum n......></asp:BoundColumn >
<asp:BoundColum n......></asp:BoundColumn >
<asp:TemplateCo lumn HeaderText="No. ">
<ItemTemplate >
</ItemTemplate>
</asp:TemplateCol umn>
</Columns>
Nick
"Bart Schelkens" <BS********@hot mail.com> wrote in message
news:eN******** ********@TK2MSF TNGP09.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.n o.spam.fsnet.co .uk> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
This is a very good article with extra datagrid info:

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

"Bart Schelkens" <BS********@hot mail.com> wrote in message
news:Om******** *****@TK2MSFTNG P12.phx.gbl...
> Jared,
>
> thx for the answer.
> My email is a valid address BS********@hotm ail.com
> So there's no problem in sending me a reply there.
>
> Thx.
> Bart
>
> "Jared" <VB***********@ email.com> wrote in message
> news:10******** *****@corp.supe rnews.com...
> >
> > 1:) You can use a datareader to fill a datalist/datagrid.
> >
> > Dim Conn As New System.Data.Sql Client.SqlConne ction
> > Conn.Connection String = "Server=YourSer ver;
> > Database=Northw ind;Trusted_Con nection=True;"
> >
> > Conn.Open()
> >
> > Dim cmd As New SqlClient.SqlCo mmand("SELECT * FROM Employees",

Conn)
> > Me.DataGrid2.Da taSource = cmd.ExecuteRead er
> > Me.DataGrid2.Da taBind()
> >
> > 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********@hot mail.com> wrote in message
> > news:%2******** ********@TK2MSF TNGP09.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
3282
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 datagrid? The reason I am asking this question is because I already created a datagrid and made its datasource a datareader, yet, could not implement sorting or paging. Any idea of how to approach it . thanks
6
5080
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 it takes much time... So I thik of use the datareader, but how can I bind the data that it is picking from the database to the datagrid??? thx...
5
5765
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
4389
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 only retrieve a page of data, eg: daCustomers.Fill(dsCustomers, (PageNum - 1) * intPageSize, intPageSize, "Customers") But I am having difficulties achieving this using a DataReader. My goal is to have a datagrid that only displays 10 rows of...
1
1557
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, columnwidth, etc.) Now I'm using vb.net, and I'm tryint to do the same
7
1789
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 there are two buttons “Save Changes” and “Cancel”. When “Save Changes” button is clicked saveRec function is called. But for some reason inside saveRec function the value of the textbox is not visible. The line Label2.Text =...
7
15009
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 MyList data is resident in a dataset table. I'm stuck and can't choose either because. If I choose ListView as my control I don't understand how to programmatically get the data from the dataset table
3
3354
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 had written out from my web apps. I can get my DataReader to read my data fine. But I wanted to use a DataGrid, but it is apparently completely different???? I can do:
1
6524
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 determine what I get loaded onto the datagrid. Please help with some code. connect.ConnectionString = strng; OleDbCommand command = new OleDbCommand("Select * from Extensions Where FilterByKey = '" + DropDownList1.SelectedItem + "'",...
0
9687
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10228
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7565
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
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 we have to send another system

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.