DataBinder.Eval() Problem in Datalist

  • 12 years ago

    Hi...

    I am using datalist. In dat i am binding label's text property like this...

    <%# DataBinder.Eval(Container.DataItem, "Cost","{0:n2}") %>

    Now in codebehind, I am using OnItemDataBound event and want to check if its value is null.. I am taking this labels value in a string & comparing it to "".  But the value dat comes in string is <%# DataBinder.Eval(Container.DataItem,"Cost","{0:n2}") %>  . Nd i want the actual value to be checked. Plz tell me how to solve this...

  • 12 years ago

     Here's a section of code that I used to 'test' what you're doing. It may help to give you a pointer in the right direction:

        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
        {       
            int x = ((Order)e.Item.DataItem).Cost;
            Response.Write(x.ToString());
        }
     

    Order is a simple class I used as the test datasource - casting it back again to access the public members.

    Dunno if this helps at all.

    Joe 

  • 12 years ago

    Hi thanx.. dat problem is solved.. Have 1 more problem. I am having a string in codebehind in which i have a table. in dat table have used 1 label. Now i am setting strikeout property to true of this label. But it has no effect. can u suggest me some way out... It  is somewhat like this...

    string str ="";

    str = "<table><tr><td><asp:label id=lblcost runat=server Text=Cost Font-Strikeout=True ></td></tr></table>";

    can u tell me why is the text in label not getting strikeout.

  • 12 years ago

    How is the str variable being output to the page?

    Joe 

  • 12 years ago

    Hi...

        Thnx for replying.. but i have removed dat label nd used span instead of dat as it was wrkng.... Thanku...

  • 12 years ago

    Good stuff Big Smile

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“There are only two kinds of languages: the ones people complain about and the ones nobody uses” - Bjarne Stroustrup