Solved

declaring item on itemdatabound event for datalist

Posted on 2008-10-31
14
296 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
  • 8
  • 6
14 Comments
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
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
Comment Utility
so i dont have to declare   "dvr"  ???  
grouping is the name of my column in my database?
0
 
LVL 1

Author Comment

by:gianitoo
Comment Utility
im getting an error that drv is not declared
0
 
LVL 22

Expert Comment

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

Author Comment

by:gianitoo
Comment Utility
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
Comment Utility
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
Comment Utility
In another word, do you display Grouping in DataList?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:gianitoo
Comment Utility
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
Comment Utility
>>>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
Comment Utility
Yes  in my label8
0
 
LVL 22

Expert Comment

by:prairiedog
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Ur the dog!!!
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now