gianitoo
asked on
declaring item on itemdatabound event for datalist
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(By Val sender As Object, ByVal e As System.Web.UI.WebControls. DataListIt emEventArg s)
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.FindCont rol("image 7"), 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
drv is not declared properly. could you please look at my code and help me declare it?
Protected Sub DataList1_ItemDataBound(By
If e.Item.ItemType = DataControlRowType.DataRow
Dim drv As System.Data.DataView = ((e.Item.DataItem,) Data.DataView)
Dim apply As Image = DirectCast(e.Item.FindCont
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
ASKER
so i dont have to declare "dvr" ???
grouping is the name of my column in my database?
grouping is the name of my column in my database?
ASKER
im getting an error that drv is not declared
Sorry.
Is "GROUPING" a label in DataList?
Is "GROUPING" a label in DataList?
ASKER
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
so if grouping = "" then i want an image to show
etc
my db querry looks like this
select grouping, picture from table
ASKER
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?
Dim drv As System.Data.DataRowView = DirectCast(e.Row.DataItem,
how do you declare in datalist?
In another word, do you display Grouping in DataList?
ASKER
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
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
>>>Grouping has 8 options in my database
I understand. My question is do you display this Grouping in your DataList, such as using Label?
I understand. My question is do you display this Grouping in your DataList, such as using Label?
ASKER
Yes in my label8
Try this. (You may also want to change If..ElseIf...ElseIf...Endi f 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
ASKER
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(By Val sender As Object, ByVal e As System.Web.UI.WebControls. DataListIt emEventArg s)
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
can you review code ?
Protected Sub DataList1_ItemDataBound(By
If e.Item.ItemType = ListItemType.Item Then
Dim apply As Image = CType(e.Item.FindControl("
Dim lbl As Label = CType(e.Item.FindControl("
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ur the dog!!!
If e.Item.ItemType = ListItemType.Item Then
Dim apply As Image = CType(e.Item.FindControl("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