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

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

  1. Guest

    Guest Guest

    That worked great, thank you so much, timkling.

    Just as a curiosity thing: is the consensus view that what is described
    below is a good and conistent code thing, a bad and "overwordy" thing, or a
    necessary byproduct of ASP.NET's design?

    I don't know anything here, but I prefer Actionscript's terse and intuitive
    syntax to absolutely or relatively target visual controls:

    _root.myDatalist.Text = processedText;

    ASP.NET's way seems a lot kludgier. Anyone know why things are done this
    way?

    -KF


    From: "timkling" <>
    Subject: RE: how to programmatically assign text to a label control within a
    da
    Date: Monday, June 05, 2006 12:37 PM

    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>
    >
    >
    >
    Guest, Jun 5, 2006
    #1
    1. Advertising

  2. Hi KF,

    Thank you for your post!

    I think this question is largely related to the different Type System of C#
    and ActionScript. There is no way for C# compiler to determine which child
    control exists in the parent control during the compile time.

    You may take a look at following article on programming language type
    system:

    http://en.wikipedia.org/wiki/Type_system


    Regards,
    Walter Wang
    Microsoft Online Community Support

    ==================================================
    When responding to posts, please "Reply to Group" via your newsreader so
    that others may learn and benefit from your issue.
    ==================================================

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Jun 6, 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. Craig
    Replies:
    1
    Views:
    3,535
  2. Will Chamberlain

    Assign Text to Footer Label

    Will Chamberlain, Oct 3, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    1,601
    Trevor Benedict R
    Oct 3, 2005
  3. Guest
    Replies:
    1
    Views:
    929
    =?Utf-8?B?dGlta2xpbmc=?=
    Jun 5, 2006
  4. Philjo

    Programmatically assign dropdownList to a GridView control

    Philjo, Sep 20, 2006, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    1,764
    Philjo
    Sep 20, 2006
  5. Knut Krueger
    Replies:
    8
    Views:
    265
    Knut Krueger
    Aug 20, 2013
Loading...

Share This Page