how to programmatically assign text to a label control within a datalist template?

Discussion in 'ASP .Net' started by Guest, Jun 5, 2006.

  1. Guest

    Guest Guest

    I have a label control that I've embedded in a datalist template. I will be
    binding data to that label.

    I want to run a string formatting function on the database text before it is
    injected into the datalist. When I try to do this, I get a "... [control]
    does not exist in the current context.

    I need to know how to target the control. If I were writing Flash
    actionscript, it would be something like

    _root.myDatalist.myLabelInsideMyDatalist.Text =
    processedTextThatIAlreadyRanThroughMyFunction

    Is this possible? Am I running into a page lifecycle thing, or?

    Thanks for any help. Actual code follows. I'm trying to inject the formatted
    variable text into lblCon_Body.

    -KF
    <asp:DataList runat="server" id="DataList1" DataKeyField="Con_ContentID"
    DataSourceID="SqlDataSource1" Width="100%" HorizontalAlign="Left"
    CellPadding="0" >

    <ItemTemplate>

    <asp:Label Text='<%# Eval("Con_Title") %>' runat="server"
    id="Con_TitleLabel" Font-Bold="True" Font-Size="Medium" />

    <br />

    <asp:Label Text='<%# Eval("Con_BylineCredit") %>' runat="server"
    id="Con_BylineCreditLabel" Font-Italic="True" Font-Size="X-Small"
    style="font-size: small; line-height: 15pt; font-style: italic; font-family:
    Arial, Verdana, Sans-serif" />

    <br />

    <br />

    <asp:Label Text='<%# Eval("Con_Body")%>' runat="server" ID="lblCon_Body"
    Font-Italic="False" Font-Size="X-Small" style="font-size: small;
    line-height: 15pt; font-style: italic; font-family: Arial, Verdana,
    Sans-serif" /><br />

    <br />

    </ItemTemplate>

    </asp:DataList>
     
    Guest, Jun 5, 2006
    #1
    1. Advertising

  2. RE: how to programmatically assign text to a label control within a da

    Yes, you can do that, but you have to get a reference to that control first,
    using FindControl(id) and casting it as a label.

    Here's an example:

    foreach(DataListItem item in MyDataList.Items){
    ((Label)item.FindControl("lblCon_Body")).Text =
    processedTextThatIAlreadyRanThroughMyFunction;
    }


    "" wrote:

    > I have a label control that I've embedded in a datalist template. I will be
    > binding data to that label.
    >
    > I want to run a string formatting function on the database text before it is
    > injected into the datalist. When I try to do this, I get a "... [control]
    > does not exist in the current context.
    >
    > I need to know how to target the control. If I were writing Flash
    > actionscript, it would be something like
    >
    > _root.myDatalist.myLabelInsideMyDatalist.Text =
    > processedTextThatIAlreadyRanThroughMyFunction
    >
    > Is this possible? Am I running into a page lifecycle thing, or?
    >
    > Thanks for any help. Actual code follows. I'm trying to inject the formatted
    > variable text into lblCon_Body.
    >
    > -KF
    > <asp:DataList runat="server" id="DataList1" DataKeyField="Con_ContentID"
    > DataSourceID="SqlDataSource1" Width="100%" HorizontalAlign="Left"
    > CellPadding="0" >
    >
    > <ItemTemplate>
    >
    > <asp:Label Text='<%# Eval("Con_Title") %>' runat="server"
    > id="Con_TitleLabel" Font-Bold="True" Font-Size="Medium" />
    >
    > <br />
    >
    > <asp:Label Text='<%# Eval("Con_BylineCredit") %>' runat="server"
    > id="Con_BylineCreditLabel" Font-Italic="True" Font-Size="X-Small"
    > style="font-size: small; line-height: 15pt; font-style: italic; font-family:
    > Arial, Verdana, Sans-serif" />
    >
    > <br />
    >
    > <br />
    >
    > <asp:Label Text='<%# Eval("Con_Body")%>' runat="server" ID="lblCon_Body"
    > Font-Italic="False" Font-Size="X-Small" style="font-size: small;
    > line-height: 15pt; font-style: italic; font-family: Arial, Verdana,
    > Sans-serif" /><br />
    >
    > <br />
    >
    > </ItemTemplate>
    >
    > </asp:DataList>
    >
    >
    >
     
    =?Utf-8?B?dGlta2xpbmc=?=, Jun 5, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dude
    Replies:
    3
    Views:
    2,093
  2. Nevyn Twyll
    Replies:
    8
    Views:
    1,970
  3. DKode
    Replies:
    0
    Views:
    2,044
    DKode
    Sep 26, 2005
  4. Guest
    Replies:
    1
    Views:
    618
    Walter Wang [MSFT]
    Jun 6, 2006
  5. Knut Krueger
    Replies:
    8
    Views:
    336
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page