Bind DataValue From Codebehind?

4 posts, 0 answers
  1. Robert
    Robert avatar
    49 posts
    Member since:
    Sep 2008

    Posted 22 Jul 2010 Link to this post

    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
  2. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 22 Jul 2010 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert
    Robert avatar
    49 posts
    Member since:
    Sep 2008

    Posted 26 Jul 2010 Link to this post

    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.
  5. Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 28 Jul 2010 Link to this post

    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
Back to Top