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

issue with databinding

1 Answer 56 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
nbushnell
Top achievements
Rank 1
nbushnell asked on 04 Feb 2009, 05:55 PM
Hello,

i am using v2008.3.1105.35

I am trying to data bind a text box in the panel bar's item template to a field in my data source. But it dose not seem to to working correctly.  Here are the important parts:

<telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Telerik" Width="800px">
    <ItemTemplate>
        <asp:TextBox ID="TextBox2" runat="server" Text='<%#  DataBinder.Eval(Container.DataItem, "ItemDesc")%>' />
    </ItemTemplate>
</telerik:RadPanelBar>
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!IsPostBack) 
        { 
            BindPanelBar(); 
            for (int i = 0; i < RadPanelBar1.Items.Count; i++) 
                RadPanelBar1.Items[i].DataBind(); 
        } 
    } 

    protected void BindPanelBar() 
    {   
      DataTable dt; 
 
// snip: code building the datatable 
 
        RadPanelBar1.DataSource = dt; 
        RadPanelBar1.DataTextField = "Title"
        RadPanelBar1.DataValueField = "ID"
        RadPanelBar1.DataFieldID = "Alt_ID"
        RadPanelBar1.DataBind(); 
 
    } 

It runs with no errors but the text box is blank. Am I doing this in the wrong order or missing a step?

If i data bind to a panel bar property it works as expected

<telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Telerik" Width="800px"
    <ItemTemplate> 
        <asp:TextBox ID="TextBox2" runat="server" Text='<%#  DataBinder.Eval(Container, "Text")%>' /> 
    </ItemTemplate> 
</telerik:RadPanelBar> 


Thanks for the help.


1 Answer, 1 is accepted

Sort by
0
nbushnell
Top achievements
Rank 1
answered on 05 Feb 2009, 04:51 PM
ok i got this working

I did not need the for loop on the page load. I just added an on item data bound event to the panel bar. And in there call the data bind method for the panel bar item.
.aspx
<telerik:RadPanelBar ID="RadPanelBar1" runat="server" Skin="Telerik" Width="800px" OnItemDataBound="RadPanelBar1_ItemDataBound"
    <ItemTemplate> 
        <asp:TextBox ID="TextBox2" runat="server" Text='<%#  DataBinder.Eval(Container.DataItem, "ItemDesc")%>' /> 
    </ItemTemplate> 
</telerik:RadPanelBar> 

page load
    protected void Page_Load(object sender, EventArgs e)  
    {  
        if (!IsPostBack)  
        {  
            BindPanelBar();  
        }  
    } 

databind function
    protected void BindPanelBar()  
    {    
      DataTable dt;  
  
// snip: code building the datatable  
  
        RadPanelBar1.DataSource = dt;  
        RadPanelBar1.DataTextField = "Title";  
        RadPanelBar1.DataValueField = "ID";  
        RadPanelBar1.DataFieldID = "Alt_ID";  
        RadPanelBar1.DataBind();  
  
    }  

on item data bound event handler
  protected void RadPanelBar1_ItemDataBound(object sender, Telerik.Web.UI.RadPanelBarEventArgs e) 
    { 
      Telerik.Web.UI.RadPanelItem r = (Telerik.Web.UI.RadPanelItem)e.Item; 
      r.DataBind(); 
    } 

happy coding

Tags
PanelBar
Asked by
nbushnell
Top achievements
Rank 1
Answers by
nbushnell
Top achievements
Rank 1
Share this question
or