myDataList_ItemDataBound

  • Thread starter Thread starter Arjen
  • Start date Start date
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!
 
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";
 
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!
 
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.
 
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!
 
Back
Top