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

Multiple sources

1 Answer 61 Views
ListView
This is a migrated thread and some comments may be shown as answers.
oprisan tudorel
Top achievements
Rank 1
oprisan tudorel asked on 28 Jun 2010, 02:30 PM
Hello!

I have a problem with a listview.

Let me detail a little more:

I have 1 listview, 1 objectdatasource and 2 SQLDatasources..

First the listeview is binded with objectdatasource.
What i want to do after and really don't know how is:

At OnItemDataBound Event, i want to Add, fields( to fill fields actually) from the 2 SQLDatasources.

The 2 SQLDataSources should use as a parameter(ID for the sql query) an item from the listview.

So at OnItemDataBound, i should take the ObjectID pass it to the SQLDataSources, and complete the fields in the listview


<telerik:RadListView ID="RadListView1" runat="server" DataSourceID="ObjectDataSource1" 
            ItemPlaceholderID="ListViewContainer" DataKeyNames="ObjectID" AllowPaging="True" OnItemDataBound="Get_rest" > 
            <LayoutTemplate> 
                <asp:PlaceHolder runat="server" id="ListViewContainer" /> 
            </LayoutTemplate> 
            <ItemTemplate> 
                <fieldset style="float: left; width: 350px; height: 250px;"
                    <legend style="font-weight: normal"><b>Company Name</b>
                        <%# Eval("ShortName")%></legend
                    <div class="details"
                        <div class="photo-container"
                            <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("WebImage") %>' 
                                AutoAdjustImageControlSize="false" Width="120px" ToolTip='<%#Eval("Description", "Photo of {0}") %>' 
                                AlternateText='<%#Eval("Description", "Photo of {0}") %>' /> 
                        </div> 
                        <div class="data-container"
 
                            <ul> 
                                
                                <li> 
                                    <label> 
                                        Short name</label> 
                                    <%# Eval("Name")%> 
                                     
                                </li> 
                                <li> 
                                    <label> 
                                        City:</label> 
                                    <%#Eval("City")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        ZIP:</label> 
                                    <%# Eval("ZIP")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        SPR:</label> 
                                    <%#Eval("SPR")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        Country:</label> 
                                    <%#Eval("NationID")%> 
                                </li> 
                                
                                <li> 
                                    <label> 
                                        Telephone:</label> 
                                    <%# Eval("Telephone")%> 
                                </li> 
                                  <li> 
                                    <label> 
                                        Mobile:</label> 
                                    <%# Eval("Mobile")%> 
                                </li> 
                                  <li> 
                                    <label> 
                                        Fax:</label> 
                                    <%# Eval("Fax")%> 
                                </li> 
                                  <li> 
                                    <label> 
                                        E-mail:</label> 
                                    <%# Eval("Email")%> 
                                </li> 
                                  <li style="display:none;"
                                     <label id="ObjID_test" runat="server" style="display:none;"
                                       <%# Eval("ObjectID")%> </label> 
                                </li> 
                                 
                                 
                            </ul> 
                        </div> 
                    </div> 
                </fieldset> 
            </ItemTemplate> 
        </telerik:RadListView> 
This is how the Listview looks like. the Objects datasource brings back: Image/Shortname/Name, one sql datasource brings back addresses and the other brings back contact types.
What i managed to do so far is to get the ID at the OnItemDatabound event. After this i am a little stuck, as i don't know what to do next.

Having to use 1 objectdatasource and 2 sqlDatasources is mandatory.



I have a little update on my solution, but it's still not working, and i don't know how ti fix it.

the aspx code looks like this now:

<telerik:RadListView ID="RadListView1" runat="server" DataSourceID="ObjectDataSource1" 
            ItemPlaceholderID="ListViewContainer" DataKeyNames="ObjectID" AllowPaging="True" OnItemDataBound="Get_rest" > 
            <LayoutTemplate> 
                <asp:PlaceHolder runat="server" id="ListViewContainer" /> 
            </LayoutTemplate> 
            <ItemTemplate> 
                <fieldset style="float: left; width: 350px; height: 250px;"
                    <legend style="font-weight: normal"><b>Company Name</b>
                        <%# Eval("ShortName")%></legend
                    <div class="details"
                        <div class="photo-container"
                            <telerik:RadBinaryImage runat="server" ID="RadBinaryImage1" DataValue='<%#Eval("WebImage") %>' 
                                AutoAdjustImageControlSize="false" Width="120px" ToolTip='<%#Eval("Description", "Photo of {0}") %>' 
                                AlternateText='<%#Eval("Description", "Photo of {0}") %>' /> 
                        </div> 
                        <div class="data-container"
                                                  <ul> 
                                
                                <li> 
                                    <label> 
                                        Short name:</label> 
                                    <%# Eval("Name")%> 
                                     
                                </li> 
                                 
                               <telerik:RadListView ID="RadListView2" runat="server" DataSourceID="SqlDataSource1" 
            ItemPlaceholderID="ListViewContainer" AllowPaging="True" > 
            <LayoutTemplate> 
                <asp:PlaceHolder runat="server" id="ListViewContainer" /> 
            </LayoutTemplate> 
            <ItemTemplate> 
               <%-- <fieldset>--%> 
                    
                         <li> 
                                    <label> 
                                        City:</label> 
                                    <%#Eval("City")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        ZIP:</label> 
                                    <%# Eval("ZIP")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        SPR:</label> 
                                         
                                    <%#Eval("SPR")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        Country:</label> 
                                    <%#Eval("NationID")%> 
                                </li> 
                             
                             
                                 
                           
                         
              <%--  </fieldset>--%> 
            </ItemTemplate> 
        </telerik:RadListView> 
                                
                                <telerik:RadListView ID="RadListView3" runat="server" DataSourceID="SqlDataSource2" 
            ItemPlaceholderID="ListViewContainer" AllowPaging="True" > 
            <LayoutTemplate> 
                <asp:PlaceHolder runat="server" id="ListViewContainer" /> 
            </LayoutTemplate> 
            <ItemTemplate> 
             
               <%-- <fieldset>--%> 
                    
                           <li> 
                                    <label> 
                                        Phone:</label> 
                                    <%# Eval("Telephone")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        Mobile:</label> 
                                    <%# Eval("Mobile")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        FAX:</label> 
                                    <%# Eval("FAX")%> 
                                </li> 
                                <li> 
                                    <label> 
                                        E-mail:</label> 
                                    <%# Eval("Email")%> 
                                </li> 
              <%--  </fieldset>--%> 
            </ItemTemplate> 
        </telerik:RadListView> 
                                                                 
                            </ul> 
                        </div> 
                    </div> 
                </fieldset> 
            </ItemTemplate> 
        </telerik:RadListView> 

and in code behind i have the onitemdatabound function:

Protected Sub Get_rest(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadListViewItemEventArgs) Handles RadListView1.ItemDataBound 
        Dim ObjID As New Integer 
        'Dim RadListColumn As New Telerik.Web.UI.RadListViewDataItemCollection 
 
 
        Dim item = TryCast(e.Item, RadListViewDataItem) 
        If item IsNot Nothing Then 
            Dim value = CInt(DataBinder.Eval(item.DataItem, "ObjectID")) 
            ObjID = value 
        End If 
        SqlDataSource1.SelectParameters("ObjectID").DefaultValue = ObjID 
        SqlDataSource2.SelectParameters("ObjectID").DefaultValue = ObjID 
 
 
 
    End Sub 

Now the problem is that all the items in the listview, have the address and the contacts of the last  ObjectID.

Ideea anyone?




1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 01 Jul 2010, 01:06 PM
Hello Oprisan ,

As you cannot modify the DataItem to which RadListViewDataItem is bound, you should instead get the additional data (by manually querying the SqlDataSources) inside ItemDataBound and manually populate the appropriate controls inside the ItemTemplate.

Kind regards,
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
Tags
ListView
Asked by
oprisan tudorel
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or