Use DataBinder.Eval inside of plain HTML tags with HTMLGenericControl?

R

Randall Parker

I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For X01</a>

or on a different instance where the user would be viewing "X05" it would looke like:

<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For X05</a>

I'm trynig to figure out how to do that using HtmlGenericControl in C# code behind.

Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A single DataRow?

But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 
E

Eliyahu Goldin

What is the origin of the instances you are refering to? Do they represent
rows in a table?

Eliyahu

Randall Parker said:
I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For
X01 said:
or on a different instance where the user would be viewing "X05" it would looke like:

<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For
X05 said:
I'm trynig to figure out how to do that using HtmlGenericControl in C# code behind.

Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A single DataRow?

But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 
R

Randall Parker

Eliyahu said:
What is the origin of the instances you are refering to? Do they represent
rows in a table?
Yes.


Eliyahu

I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For

X01 said:
or on a different instance where the user would be viewing "X05" it would

looke like:
<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For

X05 said:
I'm trynig to figure out how to do that using HtmlGenericControl in C#

code behind.
Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A

single DataRow?
But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 
E

Eliyahu Goldin

Then you should use a Repeater/DataList/DataGrid control, set its DataSource
and DataMember properties to the table where the instancs are, put the link
into the ItemTemplate and databind.

Eliyahu

Randall Parker said:
Eliyahu said:
What is the origin of the instances you are refering to? Do they represent
rows in a table?
Yes.


Eliyahu

I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For

X01 said:
or on a different instance where the user would be viewing "X05" it
would

looke like:
<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For

X05 said:
I'm trynig to figure out how to do that using HtmlGenericControl in C#

code behind.
Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A

single DataRow?
But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 
T

Tim Cartwright

I believe you can add the runat="server" to any html tag, and then it can be
cast to htmlgeneric control, or one of the more specific types. So, at that
point you would be able to add the databinder code as it would be processed
server side.

Randall Parker said:
Eliyahu said:
What is the origin of the instances you are refering to? Do they
represent
rows in a table?
Yes.


Eliyahu

I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For

X01 said:
or on a different instance where the user would be viewing "X05" it would

looke like:
<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For

X05 said:
I'm trynig to figure out how to do that using HtmlGenericControl in C#

code behind.
Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A

single DataRow?
But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 
R

Randall Parker

Eliyahu said:
Then you should use a Repeater/DataList/DataGrid control, set its DataSource
and DataMember properties to the table where the instancs are, put the link
into the ItemTemplate and databind.

1) I know the query returns only one row.

2) I do not want to use DataGrid or similar asp controls because I do NOT want a
table. I just want a single control at the bottom of the form that is a link to a
different form based on what the main record is for the current form.
Eliyahu

Eliyahu said:
What is the origin of the instances you are refering to? Do they
represent
rows in a table?
Yes.


Eliyahu

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit.com>
wrote in message

I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For

X01</a>

or on a different instance where the user would be viewing "X05" it
would
looke like:


<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For

X05</a>

I'm trynig to figure out how to do that using HtmlGenericControl in C#

code behind.


Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A

single DataRow?


But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 
R

Randall Parker

Using Asp.net v1.1 btw.

I can't do this:

protected System.Web.UI.HtmlControls.HtmlGenericControl CreateServiceLink;

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

Why can't I do this? Because DataSource is not a member of HtmlGenericControl.

I also can not do:

CreateServiceLink.DataItem = SingleRow;

since, again, DataItem is not defined for HtmlGenericControl


Therefore DataItem does not get defined and I can't make this work.

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

Is there some way to define DataItem for an HtmlGenericControl so that
DataBinder.Eval can work?

Or is there some other mechanism to do what I want to do with an HtmlGenericControl
or some other HTML control?

Tim said:
I believe you can add the runat="server" to any html tag, and then it can be
cast to htmlgeneric control, or one of the more specific types. So, at that
point you would be able to add the databinder code as it would be processed
server side.

Eliyahu said:
What is the origin of the instances you are refering to? Do they
represent
rows in a table?
Yes.


Eliyahu

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit.com>
wrote in message

I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For

X01</a>

or on a different instance where the user would be viewing "X05" it would

looke like:


<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For

X05</a>

I'm trynig to figure out how to do that using HtmlGenericControl in C#

code behind.


Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A

single DataRow?


But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 
T

Tim Cartwright

You are right, I forgot that the html controls do not support databinding.
Actually since it is one row being bound to one control, I would not
databind, I would just set the href, using the attributes collection. You
could also set the text of the hyperlink the same way.

CreateServiceLink.Attributes["href"] = SingleRow["FIELD NAME? / FIELD
INEX?"];
CreateServiceLink.InnerText = SingleRow["FIELD NAME? / FIELD INDEX?"];


Randall Parker said:
Using Asp.net v1.1 btw.

I can't do this:

protected System.Web.UI.HtmlControls.HtmlGenericControl
CreateServiceLink;

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

Why can't I do this? Because DataSource is not a member of
HtmlGenericControl.

I also can not do:

CreateServiceLink.DataItem = SingleRow;

since, again, DataItem is not defined for HtmlGenericControl


Therefore DataItem does not get defined and I can't make this work.

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

Is there some way to define DataItem for an HtmlGenericControl so that
DataBinder.Eval can work?

Or is there some other mechanism to do what I want to do with an
HtmlGenericControl or some other HTML control?

Tim said:
I believe you can add the runat="server" to any html tag, and then it can
be cast to htmlgeneric control, or one of the more specific types. So, at
that point you would be able to add the databinder code as it would be
processed server side.

Eliyahu Goldin wrote:

What is the origin of the instances you are refering to? Do they
represent
rows in a table?

Yes.


Eliyahu

"Randall Parker" <NOtechieSPAMpundit_please@future_avoidjunk_pundit.com>
wrote in message

I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For

X01</a>

or on a different instance where the user would be viewing "X05" it
would

looke like:


<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For

X05</a>

I'm trynig to figure out how to do that using HtmlGenericControl in C#

code behind.


Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A

single DataRow?


But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 
E

Eliyahu Goldin

Make a protected property GetUrl that will obtain the correct link according
to your application logic. Databind to this property:

<a id="CreateServiceLink" href="<%# GetUrl %>">Create New Service For</a>

Note, that runat="server" is not needed.

Eliyahu

Randall Parker said:
Eliyahu said:
Then you should use a Repeater/DataList/DataGrid control, set its DataSource
and DataMember properties to the table where the instancs are, put the link
into the ItemTemplate and databind.

1) I know the query returns only one row.

2) I do not want to use DataGrid or similar asp controls because I do NOT want a
table. I just want a single control at the bottom of the form that is a link to a
different form based on what the main record is for the current form.
Eliyahu

Eliyahu Goldin wrote:

What is the origin of the instances you are refering to? Do they
represent

rows in a table?

Yes.


Eliyahu

"Randall Parker"
wrote in message

I want to generate an HTML tag that will look like:

<a href="EquipmentServiceCreate.aspx?serial=X01">Create New Service For

X01</a>

or on a different instance where the user would be viewing "X05" it
would

looke like:


<a href="EquipmentServiceCreate.aspx?serial=X05">Create New Service For

X05</a>

I'm trynig to figure out how to do that using HtmlGenericControl in C#

code behind.


Can DataBinder.Eval work inside of plain HTML tags?

I'm trying to do something like this:

<a id="CreateServiceLink" runat="server"
href="'<%# "EquipmentServiceCreate.aspx?serial=" +
DataBinder.Eval(Container, "DataItem.owner_serial_num")
%>'x">Create New Service For</a>

But what is unclear to me is what I'd bind to the CreateServiceLink. A

single DataRow?


But one can not do:

DataRow SingleRow = dsTheSingleItemDataSet.Tables[0].Rows[0];
CreateServiceLink.DataSource = SingleRow;

The HTMLGenericControl does not have DataSource as a property.

So can one not do this sort of thing with plain HTML?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top