myDataList_ItemDataBound

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default myDataList_ItemDataBound

    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 Guest

  2. #2

    Default Re: myDataList_ItemDataBound

    "Arjen" <boah123@hotmail.com> wrote in message
    news:bgo8br$39n$1@news3.tilbu1.nb.home.nl...
    > 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


    Jos Guest

  3. #3

    Default Re: myDataList_ItemDataBound


    "Jos" <josnospambranders@fastmail.fm> schreef in bericht
    news:#JcZ8$0WDHA.1512@TK2MSFTNGP11.phx.gbl...
    > "Arjen" <boah123@hotmail.com> wrote in message
    > news:bgo8br$39n$1@news3.tilbu1.nb.home.nl...
    > > 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
    >
    >

    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 Guest

  4. #4

    Default Re: myDataList_ItemDataBound

    Arjen wrote:
    > 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


    Jos Guest

  5. #5

    Default Re: myDataList_ItemDataBound


    "Jos" <josnospambranders@fastmail.fm> schreef in bericht
    news:ONsABV3WDHA.1644@TK2MSFTNGP10.phx.gbl...
    > Arjen wrote:
    >
    > > 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
    >
    >

    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!




    Arjen Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139