This is a migrated thread and some comments may be shown as answers.

Bind DataValue From Codebehind?

3 Answers 189 Views
BinaryImage
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 22 Jul 2010, 02:54 PM
I have a radbinaryimage in a listview and on Radlistview1.ItemDataBound I am trying to set the DataValue to another field from my sql Query based on whether the record is "Signed" How can I do this it keeps giving me errors.

Protected Sub RadListView2_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewItemEventArgs) Handles RadListView2.ItemDataBound
       If TypeOf e.Item Is RadListViewDataItem Then
           Dim signed As Label = DirectCast(e.Item.FindControl("Label6"), Label)
           Dim pnl1 As Panel = DirectCast(e.Item.FindControl("TopPanel"), Panel)
           Dim lbl4 As Label = DirectCast(e.Item.FindControl("Label4"), Label)
           Dim pnl2 As Panel = DirectCast(e.Item.FindControl("BottomPanel"), Panel)
           Dim btn1 As Button = DirectCast(e.Item.FindControl("Button1"), Button)
           Dim menu2 As RadMenu = DirectCast(sender.findcontrol("RadMenu2"), RadMenu)
           Dim img As RadBinaryImage = DirectCast(e.Item.FindControl("RadBinaryImage4"), RadBinaryImage)
           'Dim fball As menu2.
             
           'signed.Text = "True" 'Then
           'DirectCast(e.Item.FindControl("Div1"))
           'Div1.backgroundcolor = "00CC99"
       End If
         
       If Session("Signed") = 1 Then
           Dim menu2 As RadMenu = DirectCast(sender.findcontrol("RadMenu2"), RadMenu)
           Dim fball As RadMenuItem = DirectCast(menu2.FindItemByText("QuickFax (Signed)"), RadMenuItem)
           Dim fbsigned As RadMenuItem = DirectCast(menu2.FindItemByText("QuickFax (ALL)"), RadMenuItem)
           Dim img As RadBinaryImage = DirectCast(e.Item.FindControl("RadBinaryImage4"), RadBinaryImage)
           img.DataValue =<%# Bind("SignedImage") %>
           fball.Visible = True
           fbsigned.Visible = True
       End If

3 Answers, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 22 Jul 2010, 05:01 PM
Robert,

You cannot use binding expression in code-behind.
In order to populate the RadBinaryImage control you should assign the value of the field which holds the byte array directly to the DataValue property. Similar to the following:

img.DataValue = CType(DataBinder.Eval(CType(e.Item, RadListViewDataItem).DataItem, "SignedImage"), Byte())

All the best,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Robert
Top achievements
Rank 1
answered on 26 Jul 2010, 04:19 PM
Thanks for the info however I used a case statement in my sql query to achieve what I needed. One question though COuld you give me an example of how I would set the imageurl of this control to come directly from the SQL Server. IE I have the image stored in my sql db an I would like to stream directly from the db and set the imageurl to be from the streamed SQL image.
0
Rosen
Telerik team
answered on 28 Jul 2010, 01:27 PM
Hello Robert,

As I have mentioned in my previous message, in order to use RadBinaryImage control you should first retrieve the image save in the DB as a byte array and then assign it to DataValue property of the control.
You may refer to this online demo.

Greetings,
Rosen
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
BinaryImage
Asked by
Robert
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Robert
Top achievements
Rank 1
Share this question
or