Binding Text or Value of Items in the ItemTemplate of RadListBox

6 posts, 0 answers
  1. Saquib
    Saquib avatar
    18 posts
    Member since:
    Aug 2011

    Posted 29 Apr 2013 Link to this post

    Hello,

    I have an ItemTemplate in my RadListBox with a Label and an anchor tag. I am not binding the a datasource to this RadListBox, rather adding RadListBoxItem one by one. I want the Text property of RadListBoxItem to be mapped to the asp:Label in the template and when I click on the delete anchor tag, the item should be deleted. Can someone help me on this?

    <ItemTemplate>
         <span>
               <asp:Label Text="how to bind" runat="server"></asp:Label>
         </span>
         <span>
               <
    a href="#" onclick="how to delete">Delete</a></span>
    </ItemTemplate>

    Thanks,
    Saquib
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 29 Apr 2013 Link to this post

    Hi,

    Try the following.
    aspx:
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("ID") %>'></asp:Label>

    Thanks,
    Shinu
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Saquib
    Saquib avatar
    18 posts
    Member since:
    Aug 2011

    Posted 30 Apr 2013 Link to this post

    Shinu,

     Text='<%# Eval("ID") %>'

    I am binding RadListBoxItems to the RadListBox, which has 'Text' and 'Value'. I don't have any field called ID that I could bind the text property of label.

    I tried  Text='<%# Eval("Text") %>', but it doesn't work. Can you take a look further please.

    I have also tried 
    <%# DataBinder.Eval(Container, "Text") %> and 
    
    <%# DataBinder.Eval(Container, "Attributes['Text']") %>
    
    
    None of them works.

    Thanks,
    Saquib.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 02 May 2013 Link to this post

    Hi,

    Before the template can use the ListBox item properties to bind the elements in the template, the application needs to explicitly bind the items by calling the DataBind method of RadListBox.
    c#
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RadListBox1.DataBind();
        }
    }

    Thanks,
    Shinu
  6. Jacek
    Jacek avatar
    12 posts
    Member since:
    Apr 2011

    Posted 14 May 2013 Link to this post

    I am trying to update database from RadComboBox value in template. How to do it?

    <asp:SqlDataSource ID="SqlDataSource3" runat="server"
       ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
       SelectCommand="SELECT [ID], [Name], [Order], poziom FROM [Cities1] ORDER BY [Order]"
       InsertCommand="INSERT INTO [Cities1] ([Name], [Order]) VALUES (?,?)"
       DeleteCommand="DELETE FROM [Cities1] WHERE [ID] = ?"
       UpdateCommand="UPDATE [Cities1] SET [Name] = ?, [Order] = ?, [poziom] = ? WHERE [ID] = ?"
       ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>">
    <UpdateParameters>
       <asp:Parameter Name="Name" Type="String" />
       <asp:Parameter Name="Order" Type="Int32" />
       <asp:Parameter Name="poziom" Type="Int32" />
       <asp:Parameter Name="ID" Type="Int32" />
    </UpdateParameters>
    <InsertParameters>
       <asp:Parameter Name="Name" Type="String" />
       <asp:Parameter Name="Order" Type="Int32" />
    </InsertParameters>
    <DeleteParameters>
       <asp:Parameter Name="ID" Type="Int32" />
    </DeleteParameters>
    </asp:SqlDataSource>
    <telerik:RadListBox ID="RadListBox2"
       runat="server"
       AllowAutomaticUpdates="True" 
       DataKeyField="ID"           
       DataTextField="Name" 
       DataValueField="ID"               
       DataSourceID="SqlDataSource3" AllowDelete="True" AutoPostBack="True" AutoPostBackOnDelete="True" AutoPostBackOnReorder="True" AutoPostBackOnTransfer="True" TransferToID="RadListBox1" Width="300px" >
    <ButtonSettings TransferButtons="All" position="Left"></ButtonSettings>
        <ItemTemplate>
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
             <telerik:RadComboBox ID="RadComboBox1" Runat="server" DataSourceID="SqlDataSource1" DataTextField="opis" DataValueField="id" SelectedValue='<%# Eval("poziom") %>'>
            </telerik:RadComboBox>
        </ItemTemplate>
    </telerik:RadListBox>
  7. Nencho
    Admin
    Nencho avatar
    1457 posts

    Posted 17 May 2013 Link to this post

    Hello Jacek ,

    The automatic database updates are indented to work regarding the three operations of the RadListBox : Transfer, Delete, Reorder. This is why, the functionality you attempt to achieve could not be implemented. However, I would suggest you to manually update the database at a desirable event handler of the RadComboBoxes or on a certain Button's Click event handler.

    Regards,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017