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

OnSelectedIndexChanged fail

3 Answers 138 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 2
Iron
Iron
Pierre asked on 10 Nov 2009, 11:59 PM
I try to fire the server side function when click on the image of the image librairy:

                                <telerik:RadListView runat="server" ID="RadLVPhotos" Enabled="false" Visible="true" 
                                    AllowPaging="true" PageSize="10" DataKeyNames="Id" 
                                     OnNeedDataSource="RadLVPhotos_NeedDataSource" OnSelectedIndexChanged="RadLVPhotos_SelectedIndexChanged" ItemPlaceholderID="ProductsHolder">  
                                    <LayoutTemplate> 
                                        <div id="list">  
                                            <div style="clear: both;">  
                                            </div> 
                                            <fieldset runat="server" id="ProductsHolder" /> 
                                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
                                            <div style="clear: both;">  
                                            </div> 
                                        </div> 
                                    </LayoutTemplate> 
                                    <EmptyDataTemplate> 
                                        <legend>Photos</legend>Aucune photo...  
                                    </EmptyDataTemplate> 
                                    <ItemTemplate> 
                                        <fieldset style="float: left; margin: 5px 5px 5px 5px; padding: 2px 2px 2px 2px;  
                                            background: #eeeeee" class="myClass" onmouseover="containerMouseover(this)" onmouseout="containerMouseout(this)">  
                                            <telerik:RadBinaryImage Style="cursor: pointer;" runat="server" ID="RadBinaryImage1" 
                                                DataValue='<%#Eval("Fichier.Content") %>' AlternateText='<%#Eval("Fichier.itemID") %>' Height="120px" Width="120px" 
                                                ResizeMode="Fit" onclick="" /> 
                                            <br /> 
                                            <div style="margin-top: -30px; position: fixed; display: none; width: 60px;">  
                                            </div> 
                                        </fieldset> 
                                    </ItemTemplate> 
                                </telerik:RadListView> 

    Protected Sub RadLVPhotos_SelectedIndexChanged(ByVal sender As ObjectByVal e As EventArgs)  
        Dim radLVPhotos As RadListView = DirectCast(sender, RadListView)  
 
        If radLVPhotos.SelectedItems.Count <> 0 Then 
 
        Else 
            radLVPhotos.ClearSelectedItems()  
        End If 
    End Sub 

Nothing append...

any suggestion?

3 Answers, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 11 Nov 2009, 10:41 AM
Hello Pierre,

To achieve your goal you can wrap the RadBinaryImage instance inside asp LinkButton with CommandName="Select" and empty Text value. See how this is done for the second RadListView on the 'First look' demo of the product:

http://demos.telerik.com/aspnet-ajax/listview/examples/firstlook/defaultcs.aspx

Best regards,
Sebastian
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
Pierre
Top achievements
Rank 2
Iron
Iron
answered on 11 Nov 2009, 05:44 PM
Thanks that work now. But what about extracting date from the selected item?
I try this:
I need to get the ID of the selected item in the cmdRemoveIng_Click function:
    Protected Sub RadLVPhotos_SelectedIndexChanged(ByVal sender As ObjectByVal e As EventArgs)  
        Dim radLVPhotos As RadListView = DirectCast(sender, RadListView)  
        Dim cmdRemoveImg As Button = DirectCast(RadPanelBar1.FindItemByValue("Photos").FindControl("cmdRemoveImg"), Button)  
 
        If radLVPhotos.SelectedItems.Count <> 0 Then 
            cmdRemoveImg.Enabled = True 
        Else 
            radLVPhotos.ClearSelectedItems()  
            cmdRemoveImg.Enabled = False 
        End If 
    End Sub 
 
    Protected Sub cmdRemoveImg_Click(ByVal sender As ObjectByVal e As EventArgs)  
        Dim radLVPhotos As RadListView = DirectCast(RadPanelBar1.FindItemByValue("Photos").FindControl("radLVPhotos"), RadListView)  
 
        If radLVPhotos.SelectedItems.Count <> 0 Then 
            Dim values As New Hashtable()  
            radLVPhotos.SelectedItems(0).ExtractValues(values)  
            Dim nID As Int32 = values("ID")  
            Dim scope As IObjectScope = ScopeFactory.GetPerRequestScope(HttpContext.Current)  
            Dim oProdFich As ProduitsFichier = scope.Extent(Of ProduitsFichier)().Single(Function(p As ProduitsFichier) p.Id = nID)  
            scope.Transaction.Begin()  
            scope.Remove(oProdFich)  
            scope.Transaction.Commit()  
            radLVPhotos.Rebind()  
        End If 
    End Sub 

The ExtractValues return nothing. But the SelectedItems.count = 1.
Any suggestion?
0
Sebastian
Telerik team
answered on 12 Nov 2009, 10:49 AM
Hello Pierre,

Do you use binding expressions for the controls (and ID field in particular) inside the ItemTemplate/SelectedItemTemplate of RadListView as illustrated on this online demo of the product? Thus you should be able to fetch the data as expected.

You may also provide the entire markup and code-behind implementation related to RadListView in this thread - thus I will be able to familiarize with your complete code logic and advice you further.

Best regards,
Sebastian
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
ListView
Asked by
Pierre
Top achievements
Rank 2
Iron
Iron
Answers by
Sebastian
Telerik team
Pierre
Top achievements
Rank 2
Iron
Iron
Share this question
or