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

Selecting an item from ListView

1 Answer 173 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Kamal Mostofi
Top achievements
Rank 1
Kamal Mostofi asked on 12 May 2010, 12:17 AM
Hi,
I have the following code in my asp page. I would like to click on Select button and get the logoid which is in a hidden field. but it won't work when i click on the button.
             <telerik:RadListView ID="dvlogo1" runat="server" DataSourceID="dslogo"
            ItemPlaceholderID="PlaceHolder1" AllowPaging="true" OnItemCommand="dvlogo1_ItemCommand" >
            <LayoutTemplate>
                <div class="sushibar">
                    <asp:Panel ID="SushiPanel" runat="server">
                        <div class="sushi">
                            <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                        </div>
                        <telerik:RadDataPager ID="RadDataPager1" runat="server" PageSize="10" Skin="Black">
                            <Fields>
                                <telerik:RadDataPagerButtonField FieldType="Numeric" />
                            </Fields>
                        </telerik:RadDataPager>
                    </asp:Panel>
                </div>
            </LayoutTemplate>
            <ItemTemplate>
                <div class="category">
                    <p><asp:HiddenField runat="server" ID="hidlogoid" Value='<%# Eval("logoid") %>' />
                                                
                        <%#Eval("Title") %>
                    </p>
                    <asp:Image runat="server" ID="imglogo2" Height="70px" Width="70px" ImageUrl='<%# Eval("logopath") %>' />
                     <p>
                        <asp:Button runat="server" ID="cmdselectlogo2" Text="Select" Font-Size="10px" CommandName="select" CommandArgument='<%# Eval("logopath") %>' />
                     </p>

                </div>
            </ItemTemplate>
            <SelectedItemTemplate>
                <div class="selected">
                    <p><asp:HiddenField runat="server" ID="hidlogoid1" Value='<%# Eval("logoid") %>' />
                                                
                        <%#Eval("Title") %>
                    </p>
                     <asp:Image runat="server" ID="imglogo2" Height="70px" Width="70px" ImageUrl='<%# Eval("logopath") %>' />
                     <p>
                        <asp:Button runat="server" ID="cmdselectlogo2" Text="Select" Font-Size="10px" CommandName="select" CommandArgument='<%# Eval("logopath") %>' />
                     </p>
                </div>
            </SelectedItemTemplate>
        </telerik:RadListView>

C# Code
         protected void dvlogo1_ItemCommand(object source, RadListViewCommandEventArgs e)
        {
            if (e.CommandName == RadListView.SelectCommandName)
            {
                RadListViewDataItem item = e.ListViewItem as RadListViewDataItem;
                string myValue = item.GetDataKeyValue("logoid").ToString();
            }
            //switch (e.CommandName)
            //{
            //    case "selectlogo":
            //        Session["logo"] = e.CommandArgument;
            //       // hid = (this.dvlogo1.FindControl("hidlogoid") as HiddenField).Value;
            //        Session["logoid"] = (this.dvlogo1.FindControl("hidlogoid") as HiddenField).Value;

            //        break;
            //}
        }

I appreciate your help very much.

thanks,
kamal



1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 13 May 2010, 07:55 AM
Hello Kamal,

You should use the current item as a search container instead the entire RadListView instance.

if (e.CommandName == RadListView.SelectCommandName)
{            
    Session["logoid"] = (e.ListViewItem.FindControl("hidlogoid") as HiddenField).Value;
}

Best wishes,
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
Kamal Mostofi
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or