How to change LabelText in DataList

Discussion in 'ASP .Net' started by Mirek Endys, Nov 25, 2005.

  1. Mirek Endys

    Mirek Endys Guest

    Hi all,

    I thought, that this is an usual thing, but Im wrong.

    I have a DataList control and there is a Label control. I need to change the
    Text propertz of the Label control. How to do it.
    Here is my function I want to use, but it is not working. I can Find Label
    in DataListItem, but the change is not dispalyed.


    public void ConnectionCheck(DataListItem dlItem, string connection)
    {
    Label lblSourceConnectionStringStatus =
    (Label)dlItem.FindControl("lblSourceConnectionStringStatus");

    if(!Check(connection))
    {
    lblSourceConnectionStringStatus.Text = "Connection Error";
    lblSourceConnectionStringStatus.ForeColor =
    System.Drawing.Color.Red;
    }
    else
    {
    lblSourceConnectionStringStatus.Text = "Connection OK";
    lblSourceConnectionStringStatus.ForeColor =
    System.Drawing.Color.Green;
    }
    }


    protected void dlDTDefinitions_ItemCommand(object source,
    DataListCommandEventArgs e)
    {
    CheckConnections(e.Item);
    }

    What shoud I to do to display new value of the text properties?

    Thanks
    Mirek
     
    Mirek Endys, Nov 25, 2005
    #1
    1. Advertising

  2. Hi Mirek,

    Welcome to ASPNET newsgroup.
    Regarding on the changing Lable Text in DataList items problem, I think
    this is not possible due to the DataList(also any other template databound
    control's databinding model...). The DataList's item content are generated
    from DataSource during databinding. After that, the data is stored in
    viewstate and can not be modifed directly. Also, we can not modify any
    nested sub control's properties in normal postback event. If we need to
    update the item's value in DataList, we have to change the underlying
    datasource and rebind the DataList control with the updated DataSource....

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)







    --------------------
    | From: "Mirek Endys" <>
    | Subject: How to change LabelText in DataList
    | Date: Fri, 25 Nov 2005 13:55:23 +0100
    | Lines: 42
    | X-Priority: 3
    | X-MSMail-Priority: Normal
    | X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
    | X-RFC2646: Format=Flowed; Original
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
    | Message-ID: <OKKOB#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet
    | NNTP-Posting-Host: gw.coty.cz 195.47.52.129
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet:360894
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    |
    | Hi all,
    |
    | I thought, that this is an usual thing, but Im wrong.
    |
    | I have a DataList control and there is a Label control. I need to change
    the
    | Text propertz of the Label control. How to do it.
    | Here is my function I want to use, but it is not working. I can Find
    Label
    | in DataListItem, but the change is not dispalyed.
    |
    |
    | public void ConnectionCheck(DataListItem dlItem, string connection)
    | {
    | Label lblSourceConnectionStringStatus =
    | (Label)dlItem.FindControl("lblSourceConnectionStringStatus");
    |
    | if(!Check(connection))
    | {
    | lblSourceConnectionStringStatus.Text = "Connection Error";
    | lblSourceConnectionStringStatus.ForeColor =
    | System.Drawing.Color.Red;
    | }
    | else
    | {
    | lblSourceConnectionStringStatus.Text = "Connection OK";
    | lblSourceConnectionStringStatus.ForeColor =
    | System.Drawing.Color.Green;
    | }
    | }
    |
    |
    | protected void dlDTDefinitions_ItemCommand(object source,
    | DataListCommandEventArgs e)
    | {
    | CheckConnections(e.Item);
    | }
    |
    | What shoud I to do to display new value of the text properties?
    |
    | Thanks
    | Mirek
    |
    |
    |
     
    Steven Cheng[MSFT], Nov 28, 2005
    #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. Gönen EREN

    Datalist in Datalist How?

    Gönen EREN, Aug 22, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    417
    Gönen EREN
    Aug 22, 2003
  2. acko bogicevic

    DataList in DataList

    acko bogicevic, Nov 10, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    5,543
    acko bogicevic
    Nov 11, 2003
  3. Steve Lloyd
    Replies:
    1
    Views:
    710
    Rick Spiewak
    May 26, 2004
  4. Nevyn Twyll
    Replies:
    8
    Views:
    1,916
  5. Luis Esteban Valencia
    Replies:
    1
    Views:
    496
    John Saunders
    Jan 6, 2005
Loading...

Share This Page