myDataList_ItemDataBound

A

Arjen

Hallo,

I have a hyperlink control inside this datalist.
I want to give these hyperlinks some values inside this function
myDataList_ItemDataBound.

private void myDataList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e) {
// Some code
}

How can I do that?
Can you give me some sample code?

Thanks!
 
J

Jos

Arjen said:
Hallo,

I have a hyperlink control inside this datalist.
I want to give these hyperlinks some values inside this function
myDataList_ItemDataBound.

private void myDataList_ItemDataBound(object sender,
System.Web.UI.WebControls.DataListItemEventArgs e) {
// Some code
}

How can I do that?
Can you give me some sample code?

Thanks!


Something like this:
HyperLink hl=(HyperLink)e.Item.FindControl("MyHyperLinkID");
hl.Text="my new value";
 
A

Arjen

Jos said:
Something like this:
HyperLink hl=(HyperLink)e.Item.FindControl("MyHyperLinkID");
hl.Text="my new value";


What I forgot to say is that I want to set the hyperlink control with a
value from the current row.
How can I do that?

Thanks!
 
J

Jos

Arjen said:
What I forgot to say is that I want to set the hyperlink control with
a value from the current row.
How can I do that?

Put this inside the <ItemTemplate>:

<asp:HyperLink runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"fieldname") %>'></asp:HyperLink>

This will set the Text property of the HyperLink,
but you can set other properties in the same way.

Search for help on DataBinder to find more advanced formatting options.
 
A

Arjen

Jos said:
Put this inside the <ItemTemplate>:

<asp:HyperLink runat="server" Text='<%#
DataBinder.Eval(Container.DataItem,"fieldname") %>'></asp:HyperLink>

This will set the Text property of the HyperLink,
but you can set other properties in the same way.

Search for help on DataBinder to find more advanced formatting options.


The problem is a little bit more complex, the data value is an integer that
I have to change to some text.

Example:
intNumber is comming out of the database and strValue must be set inside the
hyperlink control.
if intNumber = 1 then the strValue = "High" else strValue = "Low".

How can I do this inside code behind?

Thanks!
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top