?
Solved

declaring item on itemdatabound event for datalist

Posted on 2008-10-31
14
Medium Priority
?
306 Views
Last Modified: 2012-05-05
Got ther idea from gridview and trying to apply in my datalist.  
 drv is not declared properly.  could you please look at my code and help me declare it?

 Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
        If e.Item.ItemType = DataControlRowType.DataRow Then
            Dim drv As System.Data.DataView = ((e.Item.DataItem,) Data.DataView)
            Dim apply As Image = DirectCast(e.Item.FindControl("image7"), Image)
            If drv("GROUPING") = "LT10" Then
                apply.ImageUrl = "~/lt/lt10.jpg"
            ElseIf drv("GROUPING") = "LT15" Then
                apply.ImageUrl = "~/lt/lt15.jpg"
            ElseIf drv("GROUPING") = "LT28" Then
                apply.ImageUrl = "~/lt/lt28.jpg"
            ElseIf drv("GROUPING") = "LT40" Then
                apply.ImageUrl = "~/lt/lt40.jpg"
            ElseIf drv("GROUPING") = "LT50" Then
                apply.ImageUrl = "~/lt/lt50.jpg"
            ElseIf drv("GROUPING") = "LT70" Then
                apply.ImageUrl = "~/lt/lt70.jpg"
            End If
        End If
    End Sub
0
Comment
Question by:gianitoo
[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
  • 8
  • 6
14 Comments
 
LVL 22

Expert Comment

by:prairiedog
ID: 22850962
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
        If e.Item.ItemType = ListItemType.Item Then
            Dim apply As Image = CType(e.Item.FindControl("image7"), Image)
            If drv("GROUPING") = "LT10" Then
                apply.ImageUrl = "~/lt/lt10.jpg"
            ElseIf drv("GROUPING") = "LT15" Then
                apply.ImageUrl = "~/lt/lt15.jpg"
            ElseIf drv("GROUPING") = "LT28" Then
                apply.ImageUrl = "~/lt/lt28.jpg"
            ElseIf drv("GROUPING") = "LT40" Then
                apply.ImageUrl = "~/lt/lt40.jpg"
            ElseIf drv("GROUPING") = "LT50" Then
                apply.ImageUrl = "~/lt/lt50.jpg"
            ElseIf drv("GROUPING") = "LT70" Then
                apply.ImageUrl = "~/lt/lt70.jpg"
            End If
        End If
    End Sub
0
 
LVL 1

Author Comment

by:gianitoo
ID: 22851013
so i dont have to declare   "dvr"  ???  
grouping is the name of my column in my database?
0
 
LVL 1

Author Comment

by:gianitoo
ID: 22851030
im getting an error that drv is not declared
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 22

Expert Comment

by:prairiedog
ID: 22851078
Sorry.
Is "GROUPING" a label in DataList?
0
 
LVL 1

Author Comment

by:gianitoo
ID: 22851140
no...grouping  is a column in my database

so if grouping = ""  then  i want an image to show
etc

my db  querry looks like this
select grouping, picture  from table
0
 
LVL 1

Author Comment

by:gianitoo
ID: 22851157
I used the same concept in view grid and this how i declared it
 Dim drv As System.Data.DataRowView = DirectCast(e.Row.DataItem, Data.DataRowView)

how do you declare in datalist?
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22851173
In another word, do you display Grouping in DataList?
0
 
LVL 1

Author Comment

by:gianitoo
ID: 22851203
Grouping has 8 options in my database

that is why i  do this

       If drv("GROUPING") = "LT10" Then
               apply.ImageUrl = "~/lt/lt10.jpg"
           ElseIf drv("GROUPING") = "LT15" Then
               apply.ImageUrl = "~/lt/lt15.jpg"
           ElseIf drv("GROUPING") = "LT28" Then
               apply.ImageUrl = "~/lt/lt28.jpg"
           ElseIf drv("GROUPING") = "LT40" Then
               apply.ImageUrl = "~/lt/lt40.jpg"
           ElseIf drv("GROUPING") = "LT50" Then
               apply.ImageUrl = "~/lt/lt50.jpg"
           ElseIf drv("GROUPING") = "LT70" Then
               apply.ImageUrl = "~/lt/lt70.jpg"
           End If
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22851248
>>>Grouping has 8 options in my database

I understand. My question is do you display this Grouping in your DataList, such as using Label?
0
 
LVL 1

Author Comment

by:gianitoo
ID: 22851268
Yes  in my label8
0
 
LVL 22

Expert Comment

by:prairiedog
ID: 22851309
Try this. (You may also want to change If..ElseIf...ElseIf...Endif to Select Case statement, it is more readable)
Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
       If e.Item.ItemType = ListItemType.Item Then
           Dim apply As Image = CType(e.Item.FindControl("image7"), Image)
           Dim lbl As Label = CType(e.Item.FindControl("label8"), Label)
           If lbl.Text.Trim() = "LT10" Then
               apply.ImageUrl = "~/lt/lt10.jpg"
           ElseIf lbl.Text.Trim() = "LT15" Then
               apply.ImageUrl = "~/lt/lt15.jpg"
           ElseIf lbl.Text.Trim() = "LT28" Then
               apply.ImageUrl = "~/lt/lt28.jpg"
           ElseIf lbl.Text.Trim() = "LT40" Then
               apply.ImageUrl = "~/lt/lt40.jpg"
           ElseIf lbl.Text.Trim() = "LT50" Then
               apply.ImageUrl = "~/lt/lt50.jpg"
           ElseIf lbl.Text.Trim() = "LT70" Then
               apply.ImageUrl = "~/lt/lt70.jpg"
           End If
       End If
   End Sub

Open in new window

0
 
LVL 1

Author Comment

by:gianitoo
ID: 22851542
I did this.  I fopund an issue.  everyother item is not showing the image.  i know there is an image for each group and misteriusly it does not show every other one. .  
can you review code ?

  Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
        If e.Item.ItemType = ListItemType.Item Then
            Dim apply As Image = CType(e.Item.FindControl("image7"), Image)
            Dim lbl As Label = CType(e.Item.FindControl("label1"), Label)
            Select lbl.Text
                Case "LT10"
                    apply.ImageUrl = "~/lt/lt10.jpg"

                Case "LT15"
                    apply.ImageUrl = "~/lt/lt15.jpg"
                   
                Case "LT28"
                    apply.ImageUrl = "~/lt/lt28.jpg"
                   
                Case "LT40"
                    apply.ImageUrl = "~/lt/lt40.jpg"
                   
                Case "LT50"
                    apply.ImageUrl = "~/lt/lt50.jpg"
                   
                Case "LT70"
                    apply.ImageUrl = "~/lt/lt70.jpg"
           
            End Select
                       
        End If
    End Sub
0
 
LVL 22

Accepted Solution

by:
prairiedog earned 2000 total points
ID: 22851695
This should do:
 

Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
        If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
            Dim apply As Image = CType(e.Item.FindControl("image7"), Image)
            Dim lbl As Label = CType(e.Item.FindControl("label1"), Label)
            Select lbl.Text
                Case "LT10"
                    apply.ImageUrl = "~/lt/lt10.jpg"
 
                Case "LT15"
                    apply.ImageUrl = "~/lt/lt15.jpg"
                    
                Case "LT28"
                    apply.ImageUrl = "~/lt/lt28.jpg"
                    
                Case "LT40"
                    apply.ImageUrl = "~/lt/lt40.jpg"
                    
                Case "LT50"
                    apply.ImageUrl = "~/lt/lt50.jpg"
                    
                Case "LT70"
                    apply.ImageUrl = "~/lt/lt70.jpg"
            
            End Select
                        
        End If
    End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:gianitoo
ID: 31512069
Ur the dog!!!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 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