Any way to set ImageUrl while binding data?

5 posts, 1 answers
  1. Wei
    Wei avatar
    33 posts
    Member since:
    Oct 2008

    Posted 20 Nov 2008 Link to this post

    I am new to RadPanelBar.  I want to dynamically bind not just menu text / structure but also images. Is there any way to do that?

    Here is my test code modified from sample:
    1     protected void Page_Load(object sender, EventArgs e)  
    2         {  
    3             if(!this.IsPostBack)  
    4             {  
    5                 uxLFMenuBarML.DataTextField = "Text";  
    6                 uxLFMenuBarML.DataFieldID = "ID";  
    7                 uxLFMenuBarML.DataFieldParentID = "ParentID";  
    8                 uxLFMenuBarML.DataSource = GenerateSiteData();  
    9                 uxLFMenuBarML.DataBind();  
    10  
    11             }  
    12  
    13         }  
    14  
    15     private ArrayList GenerateSiteData()  
    16         {  
    17             ArrayList siteData = new ArrayList();  
    18             siteData.Add(new LFMenuBarDataItem(1, null"All Sites","~/images/1.jpg"));  
    19             siteData.Add(new LFMenuBarDataItem(2, 1, "Search Engines""~/images/2.jpg"));  
    20             siteData.Add(new LFMenuBarDataItem(3, 1, "News Sites""~/images/3.jpg"));  
    21             siteData.Add(new LFMenuBarDataItem(4, 2, "Yahoo""~/images/4.jpg"));  
    22             siteData.Add(new LFMenuBarDataItem(5, 2, "MSN""~/images/5.jpg"));  
    23             siteData.Add(new LFMenuBarDataItem(6, 2, "Google""~/images/6.jpg"));  
    24             siteData.Add(new LFMenuBarDataItem(7, 3, "CNN""~/images/7.jpg"));  
    25             siteData.Add(new LFMenuBarDataItem(8, 3, "BBC""~/images/8.jpg"));  
    26             siteData.Add(new LFMenuBarDataItem(9, 3, "FOX""~/images/9.jpg"));  
    27             return siteData;  
    28         }  
    29  
    30  
    31  
    32  
    33     public class LFMenuBarDataItem  
    34     {  
    35         private string _text;  
    36         private int _id;  
    37         private int? _parentId;  
    38         private string _imageUrl;  
    39         public string Text  
    40         {  
    41             get { return _text; }  
    42             set { _text = value; }  
    43         }  
    44         public int ID  
    45         {  
    46             get { return _id; }  
    47             set { _id = value; }  
    48         }  
    49         public int? ParentID  
    50         {  
    51             get { return _parentId; }  
    52             set { _parentId = value; }  
    53         }  
    54         public string ImageUrl  
    55         {  
    56             get { return _imageUrl; }  
    57             set { _imageUrl = value; }  
    58         }  
    59         public LFMenuBarDataItem(int id, int? parentId, string text, string imageUrl)  
    60         {  
    61             _id = id;  
    62             _parentId = parentId;  
    63             _text = text;  
    64             _imageUrl = imageUrl;  
    65         }  
    66     } 

  2. Answer
    Brian
    Brian avatar
    1 posts
    Member since:
    Nov 2008

    Posted 20 Nov 2008 Link to this post

    You have to implement the ItemDataBound event in the RadPanelBar.  Then use the e.Item argument to get the PanelItem being bound, and the e.Item.DataItem argument to get the arraylist item to bind to.  Then you can set other properties of the PanelItem.  See Example....

    < *.cs >
    protected void RadPanelBar1_ItemDataBound(object sender, RadPanelEventArgs e)
    {
         LFMenuBarDataItem item = (LFMenuBarDataItem)e.Item.DataItem;
         e.Item.ImageUrl = item.ImageUrl
    }

    <*.aspx>

    <telerik:RadPanelBar ID="RadPanelBar1" runat="server" OnItemDataBound="RadPanelBar1_ItemDataBound"></telerik:RadPanelBar>
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Wei
    Wei avatar
    33 posts
    Member since:
    Oct 2008

    Posted 21 Nov 2008 Link to this post

    Problem solved. Thanks Brian!
  5. Abdul Kadar
    Abdul Kadar avatar
    35 posts
    Member since:
    Oct 2008

    Posted 08 Jan 2010 Link to this post

    Hi
    I need to set the image for the panelbar items at runtime .how can i do this ? I tried the code . but it not works to me.Pls review my code and let me know how to resolve this problem.I need to set the imageurl from the sqldatasource imageurl field

     

    <telerik:RadPanelBar ID="RadPanelBar1" runat="server"
    DataFieldID="MENUCODE"
    DataFieldParentID="PARENTID"
    DataSourceID="SqlDataSource1"

     

     

    DataTextField="MENUDESCRIPTION"
    DataValueField="MENUDESCRIPTION" 
    ExpandMode="FullExpandedItem"
    DataNavigateUrlField="NAVIGATEURL">

     

     

    </telerik:RadPanelBar>

     

    asp

     

    :SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TrackConnectionString %>"

     

     

     

     

     

    SelectCommand="SELECT MENUCODE, MENUDESCRIPTION, PARENTID, COMPANYID, NAVIGATEURL FROM MENUTABLE"

     

     

     

     

     

     

    </asp:SqlDataSource>

     

  6. Simon
    Admin
    Simon avatar
    2281 posts

    Posted 10 Jan 2010 Link to this post

    Hi Abdul Kadar,

    Please see Brian's post earlier in the thread for the solution. 

    Sincerely yours,
    Simon
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017