Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Datalist Conditional Values

Posted on 2004-10-29
13
Medium Priority
?
319 Views
Last Modified: 2012-05-05
Referencing this topic: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/ASP_DOT_NET/Q_21188066.html

I have a column that has either a 1  or a 0.

If the value is 1 i want to display an asterik "*" if not, then display nothing.

But i'm using  <%# DataBinder.Eval(Container.DataItem, "Name") %>

How would I do this?
0
Comment
Question by:g9support
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
  • +1
13 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 1600 total points
ID: 12448381
Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemDataBound
        Dim decTempSum, decFinalTotal As Decimal
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim Name As String = (DataBinder.Eval(e.Item.DataItem, "Name"))
            If Name = "1" Then
            e.Item.Cells(1).Text = "*"
            Else
            e.Item.Cells(1).Text = " "
         End If
    End Sub

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12448388
assuming dg is your datagrid and its name column ordinal is 1, adjust for your column ordinal

0
 

Author Comment

by:g9support
ID: 12448423
I'm using a datalist though. Does tthe following still apply?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 15

Expert Comment

by:Thogek
ID: 12448424
Or, something funny-looking like:

    <%# ( DataBinder.Eval(Container.DataItem, "Name") == 1 ? "*" : "" ) %>

(assuming C# syntax).
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12448429
I would do it in ItmDataBound of DataList event like following:
You can do similar thing in datalist also:

private void DataList1_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)
{
      switch( e.Item.ItemType )
      {
      case ListItemType.Item:
      case ListItemType.AlternatingItem:
            Label lbl = ((Label) e.Item.FindControl( "Label1" ));  // Replace with your TextBox/Label or whatever you have
                       if( lbl.Text == 1 )
                        lbl.Text = "*";
      break;
      }
}

-tushar
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12448444
oops typo:

Private Sub dg_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dg.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim Name As String = (DataBinder.Eval(e.Item.DataItem, "Name"))
            If Name = "1" Then
            e.Item.Cells(1).Text = "*"
            Else
            e.Item.Cells(1).Text = " "
         End If
    End Sub
0
 

Author Comment

by:g9support
ID: 12448518
Here's what I'm doing:

   Private Sub dlEmpHistory_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlEmpHistory.ItemDataBound
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim Name As String = (DataBinder.Eval(e.Item.DataItem, "Name"))
            If Name = "1" Then
                e.Item.Cells(1).Text = "*"
            Else
                e.Item.Cells(1).Text = " "
            End If
        End If
    End Sub

But the IDE enviroment states I "Cells" nor "Cell" is a member of 'System.Web.UI.WebControls.DataListItem

How can do this with a DL?

Thanks, I'm almost there! Thank you all for your help.
0
 
LVL 18

Assisted Solution

by:tusharashah
tusharashah earned 400 total points
ID: 12448549
What is that you're using to Display Name inside your DataList?

You'll have to retrieve that value like following:
    Dim lbl As Label = CType(e.Item.FindControl("Label1"), Label)
    Dim tb As TextBox = CType(e.Item.FindControl("TextBox1"), TextBox)

-tushar
0
 
LVL 15

Expert Comment

by:Thogek
ID: 12448577
That still seems like a lot of work for a simple formatting that could be done inside of the <%#...%> block, but... it should certainly work, so...
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12448579
ok your gonna have to use findcontrol, sorry bout that:
 Dim PriceLabel As Label = _
                CType(e.Item.FindControl("PriceLabel"), Label)
0
 

Author Comment

by:g9support
ID: 12448581
I'm just putting it directly on the page. i'm not putting it inside of another control.

After reading your post it seems as if I need to put it in another control then?
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12448634
just make sure your using template columns like so:
<asp:DataList id="ItemsList"
           BorderColor="black"
           CellPadding="5"
           CellSpacing="5"
           RepeatDirection="Vertical"
           RepeatLayout="Table"
           RepeatColumns="3"
           ShowBorder="True"
           runat="server">

         <HeaderStyle BackColor="#aaaadd">
         </HeaderStyle>

         <AlternatingItemStyle BackColor="Gainsboro">
         </AlternatingItemStyle>

         <HeaderTemplate>

            List of items

         </HeaderTemplate>
               
         <ItemTemplate>

            Description: <br>
            <%# DataBinder.Eval(Container.DataItem, "StringValue") %>

            <br>

            Price:
            <asp:Label id="PriceLabel"
                 runat="server"/>

         </ItemTemplate>
 
      </asp:DataList>
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question