473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to bring aspx code (in HTML view) to the aspx.vb code-behind?

I have an aspx code behind page that goes something like this in the HTML
view:

<asp:HyperLink id=HyperLink1 runat="server"

NavigateUrl='<%#"mailto:" &amp;
DataBinder.Eval(Container.DataItem,"StoreEmail") &amp; "&amp;Subject=" &amp;
DataBinder.Eval(Container.DataItem,"ProductName")

....

It works. For each item in the datagrid, it displays the correct
information.

.... here is additional info, if needed ...

Public Function GetItems(ByVal cartID As String) As SqlDataReader

Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))

Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList",
myConnection)

myCommand.CommandType = CommandType.StoredProcedure

Dim parameterCartID As SqlParameter = New SqlParameter("@CartID",
SqlDbType.NVarChar, 50)

parameterCartID.Value = cartID

myCommand.Parameters.Add(parameterCartID)

myConnection.Open()

Dim result As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction)

' Return the datareader result

Return result

End Function

///////////////

The sproc is here:

CREATE PROCEDURE [dbo].[ShoppingCartList]

@CartID nvarchar (50)

AS

SELECT dbo.Products.ProductID,
dbo.Products.ProductName,
dbo.ShoppingCart.Quantity,
dbo.Products.Price,
....

FROM dbo.Products INNER JOIN
dbo.ShoppingCart ON dbo.Products.ProductID =
dbo.ShoppingCart.ProductID INNER JOIN
...

WHERE
Products.ProductID = ShoppingCart.ProductID
...

GO
_________________________________

Now I would like to bring this HTML code to code-behind page (.vb).

So, I have (the name is different because I had to use a FindControl
construct)

MailHyperLink.NavigateUrl = .... (Do I use the same quote, '<%# .... %>' ..
what do I put here??)

How do I continue?

If you could also explain the "why" for your answer ,that would be even
better.

TIA,

Paolo
Nov 19 '05 #1
6 5467
Hi Paolo:

Are you trying to bring the DataBinding statements into code behind?

This article may provide some insight:
http://odetocode.com/Articles/278.aspx

Let me know if I've misunderstood the question...

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 19 Feb 2005 08:23:07 -0500, "Paolo Pignatelli"
<Pa***@DotNetStore.com> wrote:
I have an aspx code behind page that goes something like this in the HTML
view:

<asp:HyperLink id=HyperLink1 runat="server"

NavigateUrl='<%#"mailto:" &amp;
DataBinder.Eval(Container.DataItem,"StoreEmail" ) &amp; "&amp;Subject=" &amp;
DataBinder.Eval(Container.DataItem,"ProductName ")

...

It works. For each item in the datagrid, it displays the correct
information.

... here is additional info, if needed ...

Public Function GetItems(ByVal cartID As String) As SqlDataReader

Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings(" ConnectionString"))

Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList",
myConnection)

myCommand.CommandType = CommandType.StoredProcedure

Dim parameterCartID As SqlParameter = New SqlParameter("@CartID",
SqlDbType.NVarChar, 50)

parameterCartID.Value = cartID

myCommand.Parameters.Add(parameterCartID)

myConnection.Open()

Dim result As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConn ection)

' Return the datareader result

Return result

End Function

///////////////

The sproc is here:

CREATE PROCEDURE [dbo].[ShoppingCartList]

@CartID nvarchar (50)

AS

SELECT dbo.Products.ProductID,
dbo.Products.ProductName,
dbo.ShoppingCart.Quantity,
dbo.Products.Price,
...

FROM dbo.Products INNER JOIN
dbo.ShoppingCart ON dbo.Products.ProductID =
dbo.ShoppingCart.ProductID INNER JOIN
...

WHERE
Products.ProductID = ShoppingCart.ProductID
...

GO
_________________________________

Now I would like to bring this HTML code to code-behind page (.vb).

So, I have (the name is different because I had to use a FindControl
construct)

MailHyperLink.NavigateUrl = .... (Do I use the same quote, '<%# .... %>' ..
what do I put here??)

How do I continue?

If you could also explain the "why" for your answer ,that would be even
better.

TIA,

Paolo


Nov 19 '05 #2
Yes, exactly, I am trying to bring the DataBinding statements into code
behind. Is there also a VB version of the article?

TIA,

Paolo
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:cd********************************@4ax.com...
Hi Paolo:

Are you trying to bring the DataBinding statements into code behind?

This article may provide some insight:
http://odetocode.com/Articles/278.aspx

Let me know if I've misunderstood the question...

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 19 Feb 2005 08:23:07 -0500, "Paolo Pignatelli"
<Pa***@DotNetStore.com> wrote:
I have an aspx code behind page that goes something like this in the HTML
view:

<asp:HyperLink id=HyperLink1 runat="server"

NavigateUrl='<%#"mailto:" &amp;
DataBinder.Eval(Container.DataItem,"StoreEmail" ) &amp; "&amp;Subject=" &amp;DataBinder.Eval(Container.DataItem,"ProductName ")

...

It works. For each item in the datagrid, it displays the correct
information.

... here is additional info, if needed ...

Public Function GetItems(ByVal cartID As String) As SqlDataReader

Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings(" ConnectionString"))

Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList",
myConnection)

myCommand.CommandType = CommandType.StoredProcedure

Dim parameterCartID As SqlParameter = New SqlParameter("@CartID",
SqlDbType.NVarChar, 50)

parameterCartID.Value = cartID

myCommand.Parameters.Add(parameterCartID)

myConnection.Open()

Dim result As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConn ection)

' Return the datareader result

Return result

End Function

///////////////

The sproc is here:

CREATE PROCEDURE [dbo].[ShoppingCartList]

@CartID nvarchar (50)

AS

SELECT dbo.Products.ProductID,
dbo.Products.ProductName,
dbo.ShoppingCart.Quantity,
dbo.Products.Price,
...

FROM dbo.Products INNER JOIN
dbo.ShoppingCart ON dbo.Products.ProductID =
dbo.ShoppingCart.ProductID INNER JOIN
...

WHERE
Products.ProductID = ShoppingCart.ProductID
...

GO
_________________________________

Now I would like to bring this HTML code to code-behind page (.vb).

So, I have (the name is different because I had to use a FindControl
construct)

MailHyperLink.NavigateUrl = .... (Do I use the same quote, '<%# .... %>' ...what do I put here??)

How do I continue?

If you could also explain the "why" for your answer ,that would be even
better.

TIA,

Paolo

Nov 19 '05 #3
On 19 Feb 2005, "Paolo Pignatelli" <Pa***@DotNetStore.com> postulated
in news:eo**************@TK2MSFTNGP10.phx.gbl:
Yes, exactly, I am trying to bring the DataBinding statements into code behind. Is there also a VB version of the article?

TIA,

Paolo
"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:cd********************************@4ax.com...
Hi Paolo:

Are you trying to bring the DataBinding statements into code behind?

This article may provide some insight:
http://odetocode.com/Articles/278.aspx

Let me know if I've misunderstood the question...

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 19 Feb 2005 08:23:07 -0500, "Paolo Pignatelli"
<Pa***@DotNetStore.com> wrote:
>I have an aspx code behind page that goes something like this in the HTML >view:
>
><asp:HyperLink id=HyperLink1 runat="server"
>
>NavigateUrl='<%#"mailto:" &amp;
>DataBinder.Eval(Container.DataItem,"StoreEmail" ) &amp; "&amp;Subject="
&amp; >DataBinder.Eval(Container.DataItem,"ProductName ")
>
>...
>
>It works. For each item in the datagrid, it displays the correct
>information.
>
>... here is additional info, if needed ...
>
>Public Function GetItems(ByVal cartID As String) As SqlDataReader
>
>Dim myConnection As SqlConnection = New
>SqlConnection(ConfigurationSettings.AppSettings
("ConnectionString")) >
>Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList",
>myConnection)
>
>myCommand.CommandType = CommandType.StoredProcedure
>
>Dim parameterCartID As SqlParameter = New SqlParameter("@CartID",
>SqlDbType.NVarChar, 50)
>
>parameterCartID.Value = cartID
>
>myCommand.Parameters.Add(parameterCartID)
>
>myConnection.Open()
>
>Dim result As SqlDataReader =
>myCommand.ExecuteReader(CommandBehavior.CloseConn ection)
>
>' Return the datareader result
>
>Return result
>
>End Function
>
>///////////////
>
>The sproc is here:
>
>CREATE PROCEDURE [dbo].[ShoppingCartList]
>
>@CartID nvarchar (50)
>
>AS
>
>SELECT dbo.Products.ProductID,
>dbo.Products.ProductName,
>dbo.ShoppingCart.Quantity,
>dbo.Products.Price,
>...
>
>FROM dbo.Products INNER JOIN
> dbo.ShoppingCart ON dbo.Products.ProductID = >dbo.ShoppingCart.ProductID INNER JOIN
> ...
>
> WHERE
> Products.ProductID = ShoppingCart.ProductID
> ...
>
>GO
>_________________________________
>
>
>
>Now I would like to bring this HTML code to code-behind page (.vb). >
>So, I have (the name is different because I had to use a FindControl >construct)
>
>MailHyperLink.NavigateUrl = .... (Do I use the same quote, '<%# ..... %>'
.. >what do I put here??)
>
>How do I continue?
>
>If you could also explain the "why" for your answer ,that would

be even >better.
>
>TIA,
>
>Paolo
>



You don't use the script delimiters in codebehind.

Your codebehind file is pure code. Essentially, the task is to create
a page object that implements your particular task. In this case,
looks like you wish to fill a cart, which is a datagrid?

Looks like you already have the code for creating the sqldatareader.

The datagrid accepts the SqlDataReader as it's DataSource. Given:

Dim grid As DataGrid

You'd assign the reader as:

grid.DataSource = GetItems (someCartID)

then you need to bind the two

grid.DataBind()
Is this what you're talking about? If so, take a look at the .NET
examples for ADO, of which you can see 2 or 3 examples of this kind
of thing, using codebehind with asp.net datalist type controls.

http://samples.gotdotnet.com/quickstart/aspplus/

-- ipgrunt
Nov 19 '05 #4
Hello, and Thank you!

Yes you are correct. What I am trying to do is to be able to access one of the fields of the DataGrid, (the StoreEmail one, which is a hyperlink) and then add the other information about how the hyperlink works, other parameters, so that I can pass it info such as StoreName, ProductName etc... . The hyperlink then opens the email program (mailto:) with the address, the subject, the itemnumber, etc... So, let's say that the datagriod has colums Productname and email. The Email link then opens an email, and the Subject address and other stuff filled in. If I just have a DatgaGrid
' Databind Gridcontrol with Shopping Cart Items

dgShoppingCart.DataSource = cart.GetItems(cartId)

dgShoppingCart.DataBind()

'TEST

Session("CartFull") = 1

'TEST

all the colums appear fine. I then add to the HTML page the inline code

<asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<%#"mailto:" &amp; DataBinder.Eval(Container.DataItem,"StoreEmail") &amp; "&amp;Subject=" &amp; DataBinder.Eval(Container.DataItem,"ProductName") &amp; " ID=" &amp; DataBinder.Eval(Container.DataItem,"ProductID") &amp; "&amp;Body=Test" &amp; DataBinder.Eval(Container.DataItem,"ProductName") &amp; " ID=" &amp; DataBinder.Eval(Container.DataItem,"ProductID") %>'>HyperLink</asp:HyperLink>

I get the hyperlinks the way I want them, everything works fine

BUT.... Just out of an obtuse wish to separate code better, I would like to put all the info in the HTML page in the .vb page.

All and any further help is much appreciated.

Paolo


"IPGrunt" <me@privacy.net> wrote in message news:Xn**********************************@130.133. 1.4...
On 19 Feb 2005, "Paolo Pignatelli" <Pa***@DotNetStore.com> postulated
in news:eo**************@TK2MSFTNGP10.phx.gbl:
Yes, exactly, I am trying to bring the DataBinding statements into

code
behind. Is there also a VB version of the article?

TIA,

Paolo


"Scott Allen" <sc***@nospam.odetocode.com> wrote in message
news:cd********************************@4ax.com...
Hi Paolo:

Are you trying to bring the DataBinding statements into code behind?
This article may provide some insight:
http://odetocode.com/Articles/278.aspx

Let me know if I've misunderstood the question...

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Sat, 19 Feb 2005 08:23:07 -0500, "Paolo Pignatelli"
<Pa***@DotNetStore.com> wrote:

>I have an aspx code behind page that goes something like this in the HTML >view:
>
><asp:HyperLink id=HyperLink1 runat="server"
>
>NavigateUrl='<%#"mailto:" &amp;
>DataBinder.Eval(Container.DataItem,"StoreEmail" ) &amp; "&amp;Subject="
&amp;
>DataBinder.Eval(Container.DataItem,"ProductName ")
>
>...
>
>It works. For each item in the datagrid, it displays the correct
>information.
>
>... here is additional info, if needed ...
>
>Public Function GetItems(ByVal cartID As String) As SqlDataReader
>
>Dim myConnection As SqlConnection = New
>SqlConnection(ConfigurationSettings.AppSettings

("ConnectionString")) >
>Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList",
>myConnection)
>
>myCommand.CommandType = CommandType.StoredProcedure
>
>Dim parameterCartID As SqlParameter = New SqlParameter("@CartID",
>SqlDbType.NVarChar, 50)
>
>parameterCartID.Value = cartID
>
>myCommand.Parameters.Add(parameterCartID)
>
>myConnection.Open()
>
>Dim result As SqlDataReader =
>myCommand.ExecuteReader(CommandBehavior.CloseConn ection)
>
>' Return the datareader result
>
>Return result
>
>End Function
>
>///////////////
>
>The sproc is here:
>
>CREATE PROCEDURE [dbo].[ShoppingCartList]
>
>@CartID nvarchar (50)
>
>AS
>
>SELECT dbo.Products.ProductID,
>dbo.Products.ProductName,
>dbo.ShoppingCart.Quantity,
>dbo.Products.Price,
>...
>
>FROM dbo.Products INNER JOIN
> dbo.ShoppingCart ON dbo.Products.ProductID = >dbo.ShoppingCart.ProductID INNER JOIN
> ...
>
> WHERE
> Products.ProductID = ShoppingCart.ProductID
> ...
>
>GO
>_________________________________
>
>
>
>Now I would like to bring this HTML code to code-behind page (.vb). >
>So, I have (the name is different because I had to use a FindControl >construct)
>
>MailHyperLink.NavigateUrl = .... (Do I use the same quote, '<%# .... %>'
..
>what do I put here??)
>
>How do I continue?
>
>If you could also explain the "why" for your answer ,that would

be even >better.
>
>TIA,
>
>Paolo
>




You don't use the script delimiters in codebehind.

Your codebehind file is pure code. Essentially, the task is to create
a page object that implements your particular task. In this case,
looks like you wish to fill a cart, which is a datagrid?

Looks like you already have the code for creating the sqldatareader.

The datagrid accepts the SqlDataReader as it's DataSource. Given:

Dim grid As DataGrid

You'd assign the reader as:

grid.DataSource = GetItems (someCartID)

then you need to bind the two

grid.DataBind()


Is this what you're talking about? If so, take a look at the .NET
examples for ADO, of which you can see 2 or 3 examples of this kind
of thing, using codebehind with asp.net datalist type controls.

http://samples.gotdotnet.com/quickstart/aspplus/

-- ipgrunt

Nov 19 '05 #5
On 20 Feb 2005, "Paolo Pignatelli" <Pa***@DotNetStore.com> postulated
in news:OC**************@TK2MSFTNGP12.phx.gbl:
Hello, and Thank you!

Yes you are correct. What I am trying to do is to be able to access one of the fields of the DataGrid, (the StoreEmail one, which
is a hyperlink) and then add the other information about how the
hyperlink works, other parameters, so that I can pass it info such as
StoreName, ProductName etc... . The hyperlink then opens the email
program (mailto:) with the address, the subject, the itemnumber,
etc... So, let's say that the datagriod has colums Productname and
email. The Email link then opens an email, and the Subject address
and other stuff filled in. If I just have a DatgaGrid ' Databind Gridcontrol with Shopping Cart Items

dgShoppingCart.DataSource = cart.GetItems(cartId)

dgShoppingCart.DataBind()

'TEST

Session("CartFull") = 1

'TEST

all the colums appear fine. I then add to the HTML page the inline code
<asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='<% #"mailto:" &amp; DataBinder.Eval(Container.DataItem,"StoreEmail")
&amp; "&amp;Subject=" &amp; DataBinder.Eval
(Container.DataItem,"ProductName") &amp; " ID=" &amp; DataBinder.Eval
(Container.DataItem,"ProductID") &amp; "&amp;Body=Test" &amp;
DataBinder.Eval(Container.DataItem,"ProductName") &amp; " ID=" &amp;
DataBinder.Eval(Container.DataItem,"ProductID") %>'>HyperLink
</asp:HyperLink>
I get the hyperlinks the way I want them, everything works fine

BUT.... Just out of an obtuse wish to separate code better, I would like to put all the info in the HTML page in the .vb page.
All and any further help is much appreciated.

Paolo


"IPGrunt" <me@privacy.net> wrote in message news:Xn**********************************@130.133. 1.4...
On 19 Feb 2005, "Paolo Pignatelli" <Pa***@DotNetStore.com> postulated
in news:eo**************@TK2MSFTNGP10.phx.gbl:
> Yes, exactly, I am trying to bring the DataBinding statements into
code
> behind. Is there also a VB version of the article?
>
> TIA,
>
> Paolo
>
>
> "Scott Allen" <sc***@nospam.odetocode.com> wrote in message
> news:cd********************************@4ax.com...
>> Hi Paolo:
>>
>> Are you trying to bring the DataBinding statements into code

behind?
>>
>> This article may provide some insight:
>> http://odetocode.com/Articles/278.aspx
>>
>> Let me know if I've misunderstood the question...
>>
>> --
>> Scott
>> http://www.OdeToCode.com/blogs/scott/
>>
>> On Sat, 19 Feb 2005 08:23:07 -0500, "Paolo Pignatelli"
>> <Pa***@DotNetStore.com> wrote:
>>
>> >I have an aspx code behind page that goes something like this
in the HTML
>> >view:
>> >
>> ><asp:HyperLink id=HyperLink1 runat="server"
>> >
>> >NavigateUrl='<%#"mailto:" &amp;
>> >DataBinder.Eval(Container.DataItem,"StoreEmail" ) &amp;

"&amp;Subject="
> &amp;
>> >DataBinder.Eval(Container.DataItem,"ProductName ")
>> >
>> >...
>> >
>> >It works. For each item in the datagrid, it displays the
correct >> >information.
>> >
>> >... here is additional info, if needed ...
>> >
>> >Public Function GetItems(ByVal cartID As String) As SqlDataReader >> >
>> >Dim myConnection As SqlConnection = New
>> >SqlConnection(ConfigurationSettings.AppSettings

("ConnectionString"))
>> >
>> >Dim myCommand As SqlCommand = New SqlCommand ("ShoppingCartList", >> >myConnection)
>> >
>> >myCommand.CommandType = CommandType.StoredProcedure
>> >
>> >Dim parameterCartID As SqlParameter = New

SqlParameter("@CartID", >> >SqlDbType.NVarChar, 50)
>> >
>> >parameterCartID.Value = cartID
>> >
>> >myCommand.Parameters.Add(parameterCartID)
>> >
>> >myConnection.Open()
>> >
>> >Dim result As SqlDataReader
>> >myCommand.ExecuteReader(CommandBehavior.CloseConn ection)
>> >
>> >' Return the datareader result
>> >
>> >Return result
>> >
>> >End Function
>> >
>> >///////////////
>> >
>> >The sproc is here:
>> >
>> >CREATE PROCEDURE [dbo].[ShoppingCartList]
>> >
>> >@CartID nvarchar (50)
>> >
>> >AS
>> >
>> >SELECT dbo.Products.ProductID,
>> >dbo.Products.ProductName,
>> >dbo.ShoppingCart.Quantity,
>> >dbo.Products.Price,
>> >...
>> >
>> >FROM dbo.Products INNER JOIN
>> > dbo.ShoppingCart ON

dbo.Products.ProductID
>> >dbo.ShoppingCart.ProductID INNER JOIN
>> > ...
>> >
>> > WHERE
>> > Products.ProductID = ShoppingCart.ProductID
>> > ...
>> >
>> >GO
>> >_________________________________
>> >
>> >
>> >
>> >Now I would like to bring this HTML code to code-behind page

(.vb).
>> >
>> >So, I have (the name is different because I had to use a

FindControl
>> >construct)
>> >
>> >MailHyperLink.NavigateUrl = .... (Do I use the same quote, '<%
# .... %>'
> ..
>> >what do I put here??)
>> >
>> >How do I continue?
>> >
>> >If you could also explain the "why" for your answer ,that
would be even
>> >better.
>> >
>> >TIA,
>> >
>> >Paolo
>> >
>>
>
>


You don't use the script delimiters in codebehind.

Your codebehind file is pure code. Essentially, the task is to create a page object that implements your particular task. In this case,
looks like you wish to fill a cart, which is a datagrid?

Looks like you already have the code for creating the sqldatareader.
The datagrid accepts the SqlDataReader as it's DataSource. Given:

Dim grid As DataGrid

You'd assign the reader as:

grid.DataSource = GetItems (someCartID)

then you need to bind the two

grid.DataBind()
Is this what you're talking about? If so, take a look at the .NET
examples for ADO, of which you can see 2 or 3 examples of this kind of thing, using codebehind with asp.net datalist type controls.

http://samples.gotdotnet.com/quickstart/aspplus/

-- ipgrunt

------=_NextPart_000_0008_01C51727.C29BF010
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-

1"> <META content="MSHTML 6.00.3790.259" name=GENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=Arial size=2>Hello, and Thank you!</FONT></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>Yes you are correct.&nbsp; What I am trying to do is to be able to access one of the fields of the DataGrid, (the StoreEmail one, which is a hyperlink) and then add the other information about how the hyperlink works, other parameters, so that I can pass it info such as StoreName, ProductName etc... . The hyperlink then opens the email program (mailto:) with the address, the subject, the itemnumber, etc... So, let's say that the datagriod has colums Productname and email.&nbsp; The Email link then opens an email, and the Subject address and other stuff filled in.&nbsp; If I just have a DatgaGrid </FONT></DIV>
<DIV>
<P><FONT face=Arial size=2>' Databind Gridcontrol with Shopping Cart Items</FONT></P>
<P><FONT face=Arial size=2>dgShoppingCart.DataSource =
cart.GetItems(cartId)</FONT></P>
<P><FONT face=Arial size=2>dgShoppingCart.DataBind()</FONT></P>
<P><FONT face=Arial size=2>'TEST</FONT></P>
<P><FONT face=Arial size=2>Session("CartFull") = 1</FONT></P>
<P><FONT face=Arial size=2>'TEST</FONT></P>
<P><FONT face=Arial size=2>all the colums appear fine. I then add to the HTML page the inline code</FONT></P>
<P><FONT face=Arial size=2>&lt;asp:HyperLink id=HyperLink1 runat="server" NavigateUrl='&lt;%#"mailto:" &amp;amp;
DataBinder.Eval(Container.DataItem,"StoreEmail") &amp;amp; "&amp;amp;Subject=" &amp;amp; DataBinder.Eval(Container.DataItem,"ProductName") &amp;amp; " ID=" &amp;amp; DataBinder.Eval(Container.DataItem,"ProductID") &amp;amp;
"&amp;amp;Body=Test" &amp;amp; DataBinder.Eval (Container.DataItem,"ProductName") &amp;amp; " ID=" &amp;amp; DataBinder.Eval (Container.DataItem,"ProductID") %&gt;'&gt;HyperLink&lt;/asp:HyperLink&gt;</FONT></P>
<P><FONT face=Arial size=2>I get the hyperlinks the way I want them, everything works fine</FONT></P>
<P><FONT face=Arial size=2><STRONG>BUT</STRONG>.... Just out of an obtuse wish to separate code better, I would like to put all the info in the HTML page in the&nbsp; .vb page.&nbsp; </FONT></P>
<P><FONT face=Arial size=2>All and any further help is much
appreciated.</FONT></P>
<P><FONT face=Arial size=2></FONT>&nbsp;</P>
<P><FONT face=Arial size=2>Paolo</FONT></P></DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2></FONT>&nbsp;</DIV>
<DIV><FONT face=Arial size=2>"IPGrunt" &lt;</FONT><A
href="mailto:me@privacy.net"><FONT face=Arial
size=2>me@privacy.net</FONT></A><FONT face=Arial size=2>&gt; wrote in message </FONT><A href="news:Xns96029E3D2E171swiss127army001wrenc@ 130.133.1.4"><FONT face=Arial
size=2>news:Xn**********************************@1 30.133.1.4</FONT> </A><FONT face=Arial size=2>...</FONT></DIV><FONT face=Arial size=2>&gt; On 19 Feb 2005, "Paolo Pignatelli" &lt;</FONT><A href="mailto:Pa***@DotNetStore.com"><FONT face=Arial size=2>Pa***@DotNetStore.com</FONT></A><FONT face=Arial size=2>&gt; postulated <BR>&gt; in </FONT><A
href="news:eo**************@TK2MSFTNGP10.phx.gbl"> <FONT face=Arial
size=2>news:eo**************@TK2MSFTNGP10.phx.gbl</FONT></A><FONT face=Arial size=2>:<BR>&gt; <BR>&gt; &gt; Yes, exactly, I am trying to bring the DataBinding statements into <BR>&gt; code<BR>&gt; &gt; behind. Is there also a VB version of the article?<BR>&gt; &gt; <BR>&gt; &gt; TIA,<BR>&gt; &gt; <BR>&gt; &gt; Paolo<BR>&gt; &gt; <BR>&gt; &gt; <BR>&gt; &gt; "Scott Allen" &lt;</FONT><A href="mailto:sc***@nospam.odetocode.com"><FONT face=Arial
size=2>sc***@nospam.odetocode.com</FONT></A><FONT face=Arial size= 2>&gt; wrote in message<BR>&gt; &gt; </FONT><A
href="news:cd********************************@4ax. com"><FONT face=Arial size=2>news:cd********************************@4ax .com</FONT></A> <FONT face=Arial size=2>...<BR>&gt; &gt;&gt; Hi Paolo:<BR>&gt; &gt;&gt; <BR>&gt; &gt;&gt; Are you trying to bring the DataBinding statements into code <BR>&gt; behind?<BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt; This article may provide some insight:<BR>&gt; &gt;&gt; </FONT><A
href="http://odetocode.com/Articles/278.aspx"><FONT face=Arial
size=2>http://odetocode.com/Articles/278.aspx</FONT></A><BR><FONT face=Arial size=2>&gt; &gt;&gt;<BR>&gt; &gt;&gt; Let me know if I've misunderstood the question...<BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt; --<BR>&gt; &gt;&gt; Scott<BR>&gt; &gt;&gt; </FONT><A href="http://www.OdeToCode.com/blogs/scott/"> <FONT face=Arial size=2>http://www.OdeToCode.com/blogs/scott/</FONT></A><BR><FONT face=Arial size=2>&gt; &gt;&gt;<BR>&gt; &gt;&gt; On Sat, 19 Feb 2005 08:23:07 -0500, "Paolo Pignatelli"<BR>&gt; &gt;&gt; &lt;</FONT><A
href="mailto:Pa***@DotNetStore.com"><FONT face=Arial
size=2>Pa***@DotNetStore.com</FONT></A><FONT face=Arial size=2>&gt;
wrote:<BR>&gt; &gt;&gt;<BR>&gt; &gt;&gt; &gt;I have an aspx code behind page that goes something like this in <BR>&gt; the HTML<BR>&gt; &gt;&gt;
&gt;view:<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt; &lt;asp:HyperLink id=HyperLink1 runat="server"<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt;
&gt;NavigateUrl='&lt;%#"mailto:" &amp;amp;<BR>&gt; &gt;&gt;
&gt;DataBinder.Eval(Container.DataItem,"StoreEmail ") &amp;amp; <BR> &gt; "&amp;amp;Subject="<BR>&gt; &gt; &amp;amp;<BR>&gt; &gt;&gt;
&gt;DataBinder.Eval(Container.DataItem,"ProductNam e")<BR>&gt; &gt; &gt; &gt;<BR>&gt; &gt;&gt; &gt;...<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt; &gt; &gt;It works. For each item in the datagrid, it displays the correct<BR> &gt; &gt;&gt; &gt;information.<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;... here is additional info, if needed ...<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt; &gt; &gt;Public Function GetItems(ByVal cartID As String) As SqlDataReader<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;Dim myConnection As SqlConnection = New <BR>&gt; &gt;&gt; &gt;SqlConnection(ConfigurationSettings.AppSetting s<BR> &gt; ("ConnectionString"))<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;Dim myCommand As SqlCommand = New SqlCommand("ShoppingCartList",<BR>&gt; &gt;&gt;
&gt;myConnection)<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt;
&gt;myCommand.CommandType = CommandType.StoredProcedure<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID",<BR>&gt; &gt;&gt; &gt;SqlDbType.NVarChar, 50)<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;parameterCartID.Value = cartID <BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt;
&gt;myCommand.Parameters.Add(parameterCartID)<BR>& gt; &gt;&gt; &gt; <BR>&gt; &gt;&gt; &gt;myConnection.Open()<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt; &gt; &gt;Dim result As SqlDataReader =<BR>&gt; &gt;&gt;
&gt;myCommand.ExecuteReader(CommandBehavior.CloseC onnection)<BR> &gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;' Return the datareader result<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;Return result<BR>&gt; &gt;&gt; &gt;<BR> &gt; &gt;&gt; &gt;End Function<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt;
&gt;///////////////<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;The sproc is here:<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;CREATE PROCEDURE
[dbo].[ShoppingCartList]<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;@CartID nvarchar (50)<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;AS<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;SELECT&nbsp;&nbsp;&nbsp;&nbsp;
dbo.Products.ProductID,<BR>&gt; &gt;&gt; &gt;dbo.Products.ProductName,<BR>&gt; &gt;&gt; &gt;dbo.ShoppingCart.Quantity,<BR>&gt; &gt;&gt;
&gt;dbo.Products.Price,<BR>&gt; &gt;&gt; &gt;...<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;FROM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; dbo.Products INNER JOIN<BR>&gt; &gt;&gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp; dbo.ShoppingCart ON dbo.Products.ProductID <BR>&gt; =<BR>&gt; &gt; &gt; &gt;dbo.ShoppingCart.ProductID INNER JOIN<BR>&gt; &gt;&gt;
&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt; WHERE<BR>&gt; &gt; &gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Products.ProductID =
ShoppingCart.ProductID<BR>&gt; &gt;&gt; &gt;&nbsp;&nbsp;&nbsp; &nbsp; ...<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;GO<BR>&gt; &gt;&gt;
&gt;_________________________________<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;Now I would like to bring this HTML code to code-behind page <BR>&gt; (.vb).<BR>&gt; &gt;&gt; &gt; <BR>&gt; &gt;&gt; &gt;So, I have (the name is different because I had to use a <BR>&gt; FindControl<BR>&gt; &gt;&gt; &gt;construct)<BR>&gt; &gt;&gt; &gt; <BR>&gt; &gt;&gt; &gt;MailHyperLink.NavigateUrl = .... (Do I use the same quote, '&lt;%# <BR>&gt; .... %&gt;'<BR>&gt; &gt; ..<BR>&gt; &gt;&gt; &gt;what do I put here??)<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;How do I continue?<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;If you could also explain the "why" for your answer ,that would <BR>&gt; be even<BR>&gt; &gt;&gt; &gt;better. <BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt; &gt;TIA,<BR>&gt; &gt;&gt; &gt;<BR> &gt; &gt;&gt; &gt;Paolo<BR>&gt; &gt;&gt; &gt;<BR>&gt; &gt;&gt;<BR>&gt; &gt; <BR> &gt; &gt; <BR>&gt; <BR>&gt; You don't use the script delimiters in codebehind. <BR>&gt; <BR>&gt; Your codebehind file is pure code. Essentially, the task is to create <BR>&gt; a page object that implements your particular task. In this case, <BR>&gt; looks like you wish to fill a cart, which is a datagrid? <BR>&gt; <BR>&gt; Looks like you already have the code for creating the
sqldatareader.<BR>&gt; <BR>&gt; The datagrid accepts the SqlDataReader as it's DataSource. Given:<BR>&gt; <BR>&gt; Dim grid As DataGrid<BR>&gt; <BR>&gt; You'd assign the reader as:<BR>&gt; <BR>&gt; grid.DataSource = GetItems
(someCartID)<BR>&gt; <BR>&gt; then you need to bind the two<BR>&gt; <BR>&gt; grid.DataBind()<BR>&gt; <BR>&gt; <BR>&gt; Is this what you're talking about? If so, take a look at the .NET <BR>&gt; examples for ADO, of which you can see 2 or 3 examples of this kind <BR>&gt; of thing, using codebehind with asp.net datalist type controls.<BR>&gt; <BR>&gt; </FONT><A
href="http://samples.gotdotnet.com/quickstart/aspplus/"><FONT face=Arial size=2>http://samples.gotdotnet.com/quickstart/aspplus/</FONT></A> <BR><FONT face=Arial size=2>&gt; <BR>&gt; -- ipgrunt</FONT></BODY></HTML>

------=_NextPart_000_0008_01C51727.C29BF010--


Honestly, I believe you are doing this correct way. In my philosophy
of code design, (which I believe is similar to M$ thinking), the
codebehind page serves up the data while the ASPX page formats and
displays the data.

But, if you really want to, you can build the values for the
Hyperlink control in codebehind. The overal scheme is to read the
SqlDataReader values and assign to the Webcontrol.

First you must read the SqlDataReader values....It is convenient to
place them in local variables for this example, (but not necessary)

Dim StoreEmail As String
Dim ProductName As String
Dim ProductID As Int
Then assume a SqlDataReader as so:
Dim SqlDataReader As myReader = cart.GetItems(cartId)
you need to test if it was successful:
If myReader.HasData Then
Then, inside this If statement, read the data.
myReader.Read()
This loads the reader with the first row of data (only one row if
your Sproc worked properly). You then read the values into your local
variables IN THE ORDER IN WHICH THEY ARE ASSIGNED WITHIN THE SPROC.
This is important. So, if your SQL statement is:

SELECT StoreEmail, ProductName, ProductID FROM Products WHERE
ProductID = @ProductID
then you read them in this order:
StoreEmail = myReader.GetString(0)
ProductName = myReader.GetString (1)
ProductID = myReader.GetInt32 (2)
Don't forget to close the reader...

myReader.Close()

(By the way, when you open the reader with the
CommandBehavior.CloseConnection argument, like this (in C#):
SqlDataReader rdr =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction);
then the connection will close when the reader closes. This is
important as you will usually return a reader from a business or data
object (using n-tier design), and no longer have access to the
connection. Even with garbage collection, you must close those
connections when finished with them.)
Now you can build your link string for the web control:
HyperLink1.NavigateUrl = "mailto: " & StoreEmail
& "&amp;Subject=" & ProductName
& "&amp;ID=" & ProductID.ToString()
When the codebehind finishes, the page is set with this link. You
might do this in the PageLoad method, or in the delegate responding
to a button push.

So, please excuse my syntactical mistakes in VB (I code in C# most of
the time), but I hope you get the idea.

Again, there is nothing wrong with how you are doing this in ASPX.
But, if you want to use codebehind, you can because of the wonderful
design of WebControls that make them all objects and how dotnet
provides access to all the fields.

Have fun!

-- ipgrunt

Nov 19 '05 #6
Wow! Thank you ever so much not only for the programming help, but also in
explaining the philosophy of how the code is divided.

Paolo

(snip)
Honestly, I believe you are doing this correct way. In my philosophy
of code design, (which I believe is similar to M$ thinking), the
codebehind page serves up the data while the ASPX page formats and
displays the data.

But, if you really want to, you can build the values for the
Hyperlink control in codebehind. The overal scheme is to read the
SqlDataReader values and assign to the Webcontrol.

First you must read the SqlDataReader values....It is convenient to
place them in local variables for this example, (but not necessary)

Dim StoreEmail As String
Dim ProductName As String
Dim ProductID As Int
Then assume a SqlDataReader as so:
Dim SqlDataReader As myReader = cart.GetItems(cartId)
you need to test if it was successful:
If myReader.HasData Then
Then, inside this If statement, read the data.
myReader.Read()
This loads the reader with the first row of data (only one row if
your Sproc worked properly). You then read the values into your local
variables IN THE ORDER IN WHICH THEY ARE ASSIGNED WITHIN THE SPROC.
This is important. So, if your SQL statement is:

SELECT StoreEmail, ProductName, ProductID FROM Products WHERE
ProductID = @ProductID
then you read them in this order:
StoreEmail = myReader.GetString(0)
ProductName = myReader.GetString (1)
ProductID = myReader.GetInt32 (2)
Don't forget to close the reader...

myReader.Close()

(By the way, when you open the reader with the
CommandBehavior.CloseConnection argument, like this (in C#):
SqlDataReader rdr =
myCommand.ExecuteReader(CommandBehavior.CloseConne ction);
then the connection will close when the reader closes. This is
important as you will usually return a reader from a business or data
object (using n-tier design), and no longer have access to the
connection. Even with garbage collection, you must close those
connections when finished with them.)
Now you can build your link string for the web control:
HyperLink1.NavigateUrl = "mailto: " & StoreEmail
& "&amp;Subject=" & ProductName
& "&amp;ID=" & ProductID.ToString()
When the codebehind finishes, the page is set with this link. You
might do this in the PageLoad method, or in the delegate responding
to a button push.

So, please excuse my syntactical mistakes in VB (I code in C# most of
the time), but I hope you get the idea.

Again, there is nothing wrong with how you are doing this in ASPX.
But, if you want to use codebehind, you can because of the wonderful
design of WebControls that make them all objects and how dotnet
provides access to all the fields.

Have fun!

-- ipgrunt

Nov 19 '05 #7

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

Similar topics

1
by: VB Programmer | last post by:
When I go from HTML view (in a webform) to Design View I get the following error: Could not open in Design view. Quote values differently inside a '<% ... "value" ... %>' block. I know exactly...
1
by: Michael | last post by:
Can someone help me figure this out, I'm using the Visual Studio.NET 2003 IDE to develop asp.net pages, I've got the toolbox open to display all the "Web Forms" elements Here is my problem, on...
0
by: Ziyad Makki | last post by:
Hello, I have created a Web Composite Control. I have also created a designer class that is used to render the control at design time. All though it dose work, I have been experiencing some...
6
by: Thomas Andersson | last post by:
Hi all, I've been thinking of about adding new languages to our website and is currently investigating how this could be done. And I know that one way to go would be to create new aspx-pages...
2
by: louise raisbeck | last post by:
Hi there. I am a little confused. SelectedValue is a property of ListBox and dropdownlist. However it isnt in the list of properties in intellisence (html view i am not talking about code behind...
2
by: Matthias H. | last post by:
Hi guys, Our team has a very strange problem. I hope anybody can help. We have a class called webpage and all our aspx-pages bases on it. Then we have a SYS.IO.File Class which have a...
2
by: Shahriar | last post by:
Is there a way for my HTML not to be reformatted when I switch between the Design view and the HTML view? Thanks Shahriar
8
by: Mr Flibble | last post by:
I can embed code within <% %> within my page or put it in the .aspx.cs file (perhaps within the load method). What are the advantages over each? Background: I have some XML and I want to...
3
by: Rolf Welskes | last post by:
Hello, this is a hint only. If you make a custom control for example witch generates code <div......</div> and I put such a control in a page then in html-view of the aspx-file I could...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.