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

Template with Attributes not showing data in List

5 Answers 135 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Heath Brown
Top achievements
Rank 1
Heath Brown asked on 06 Nov 2009, 06:42 PM
Hello,

I have a RadList populated by an SQLDatasource that looks like this:

<asp:SqlDataSource ID="dsObjectives" runat="server"   
        ConnectionString="<%$ ConnectionStrings:MentorDBConnectionString %>"   
        DeleteCommand="DELETE FROM [ObjAssignment] WHERE [ObjAssign_ID] = @ObjAssign_ID"   
        InsertCommand="INSERT INTO [ObjAssignment] ([Role_ID], [Topic_ID], [Objective_ID], [SortOrder]) VALUES (@Role_ID, @Topic_ID, @Objective_ID, @SortOrder)"   
        SelectCommand="SELECT ObjAssignment.ObjAssign_ID, ObjAssignment.Role_ID, ObjAssignment.Topic_ID, ObjAssignment.Objective_ID, ObjAssignment.SortOrder, Objectives.[Content], Categories.CategoryName, Topics.TopicName FROM ObjAssignment INNER JOIN Objectives ON ObjAssignment.Objective_ID = Objectives.Objective_ID INNER JOIN Topics ON ObjAssignment.Topic_ID = Topics.Topic_ID INNER JOIN Categories ON Objectives.Category_ID = Categories.Category_ID WHERE (ObjAssignment.Role_ID = @Role_ID) ORDER BY ObjAssignment.SortOrder"   
        UpdateCommand="UPDATE [ObjAssignment] SET [Role_ID] = @Role_ID, [Topic_ID] = @Topic_ID, [Objective_ID] = @Objective_ID, [SortOrder] = @SortOrder WHERE [ObjAssign_ID] = @ObjAssign_ID">  
        <SelectParameters> 
            <asp:ControlParameter ControlID="comboRole" DefaultValue="2" Name="Role_ID"   
                PropertyName="SelectedValue" Type="Int32" /> 
            <asp:ControlParameter ControlID="comboTopics" DefaultValue="0" Name="Topic_ID"   
                PropertyName="SelectedValue" Type="Int32" /> 
        </SelectParameters> 
        <DeleteParameters> 
            <asp:Parameter Name="ObjAssign_ID" Type="Int32" /> 
        </DeleteParameters> 
        <UpdateParameters> 
            <asp:Parameter Name="Role_ID" Type="Int32" /> 
            <asp:Parameter Name="Topic_ID" Type="Int32" /> 
            <asp:Parameter Name="Objective_ID" Type="Int32" /> 
            <asp:Parameter Name="SortOrder" Type="Int32" /> 
            <asp:Parameter Name="ObjAssign_ID" Type="Int32" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:Parameter Name="Role_ID" Type="Int32" /> 
            <asp:Parameter Name="Topic_ID" Type="Int32" /> 
            <asp:Parameter Name="Objective_ID" Type="Int32" /> 
            <asp:Parameter Name="SortOrder" Type="Int32" /> 
        </InsertParameters> 
    </asp:SqlDataSource> 

Here is the code for my RadListBox:

<telerik:RadListBox ID="listObjectives" runat="server"   
                                        AllowAutomaticUpdates="True" AllowReorder="True" AutoPostBackOnReorder="True"   
                                        DataKeyField="ObjAssign_ID" DataSortField="SortOrder"   
                                        DataSourceID="dsObjectives" DataTextField="Content"   
                                        DataValueField="ObjAssign_ID" EnableDragAndDrop="True" Skin="Office2007"   
                                        Width="100%" style="top: 0px; left: 0px" 
                                        onitemdatabound="listObjectives_ItemDataBound"   
                                        EmptyMessage="No Objectives Found" Height="375px"   
                                        onreordered="listObjectives_Reordered">  
                                        <ItemTemplate> 
                                        <table width="423" border="0" cellpadding="1" cellspacing="1">  
      <tr> 
        <td width="2%" align="center" valign="top"><img src="images/iconTopicItems.png" alt="" width="16" height="16" hspace="2" /></td>  
        <td width="98%" valign="top"><strong><%# DataBinder.Eval(Container, "Text")%></strong><br /> 
         <%# DataBinder.Eval(Container, "Attributes['Topic']")%>  - <%# DataBinder.Eval(Container, "Attributes['Category']")%></td>  
      </tr> 
    </table> 
                                        </ItemTemplate> 
                                        <EmptyMessageTemplate> 
                                            No Objectives Found  
                                        </EmptyMessageTemplate> 
                                    </telerik:RadListBox> 

When I try to run this, the Objective name shows up as it is supposed to, but the TopicName and CategoryName don't display in the list (it is empty in those areas).  I have this in my codebehind:

protected void listObjectives_ItemDataBound(object sender, Telerik.Web.UI.RadListBoxItemEventArgs e)  
        {  
            DataRowView dsObjectivesRow = (DataRowView)e.Item.DataItem;  
            e.Item.Attributes.Add("Topic", dsObjectivesRow["TopicName"].ToString());  
            e.Item.Attributes.Add("Category", dsObjectivesRow["CategoryName"].ToString());  
 
        } 

Can anyone tell me what I'm missing?  This is urgent, as it is for a project that is due very soon.  Help! :)

5 Answers, 1 is accepted

Sort by
0
Heath Brown
Top achievements
Rank 1
answered on 11 Nov 2009, 02:33 PM
Do I need to put in a ticket instead?
0
Veselin Vasilev
Telerik team
answered on 11 Nov 2009, 04:06 PM
Hello Heath Brown,

In Page_Load call the DataBind() method of the listbox.

Let us know if this helps.

Best wishes,
Veselin Vasilev
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.
0
Heath Brown
Top achievements
Rank 1
answered on 11 Nov 2009, 06:43 PM
Hello,

I tried the recommendation mentioned above.  If I run the query on the SQL server with a Role_ID manually set, it gives me a topicname and category name for each item - so I know the data is there.  It still isn't showing up though.  Here is a link to how it looks right now:

http://www.coldsuncreations.com/images/missingdata.jpg

I put this in the Page_Load:

listObjectives.DataBind(); 

Anything else you can suggest?  Thank you for your help! :)

Should I try something with ItemDataBound instead?
0
Heath Brown
Top achievements
Rank 1
answered on 12 Nov 2009, 05:35 PM
According to everything else I've read, this shouldn't be that hard and the above code should work.  I guess I'll turn in a ticket as this was posted almost a week ago and I have a client who needs it done rather soon.
0
Veselin Vasilev
Telerik team
answered on 13 Nov 2009, 09:37 AM
Hello Heath Brown,

I already replied to your ticket:

Actually you need to bind every item itself in Page_Load:

protected void Page_Load(object sender, EventArgs e)
{
    RadListBox1.DataBind();
    foreach (RadListBoxItem item in RadListBox1.Items)
        item.DataBind();
}


Alternatively, the easier way would be to define the template using the Container.DataItem property:

<%# DataBinder.Eval(Container.DataItem, "TopicName")%>  - <%# DataBinder.Eval(Container.DataItem, "CategoryName")%>

In this case you do not need the ItemDataBound event handler and no code in page_load.


Greetings,
Veselin Vasilev
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.
Tags
ListBox
Asked by
Heath Brown
Top achievements
Rank 1
Answers by
Heath Brown
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or