Getting Select Item to Work

5 posts, 0 answers
  1. Andrey
    Andrey avatar
    18 posts
    Member since:
    Jun 2012

    Posted 26 Mar 2012 Link to this post

    I have this tiny project where I'm trying to get "Select Item" to work in RadListView. However, I am not having any luck with it. The RadListView loads and populates correctly, but when I click on an object, it does not change to the "SelectedItem" template for the object. What am I doing wrong?

    Thank you for any help,
    Andrey

    Default.aspx:
    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
        CodeBehind="Default.aspx.cs" Inherits="ListViewTest._Default" %>
     
    <asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
    </asp:Content>
    <asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
        <asp:ObjectDataSource ID="m_oDataSource" runat="server" SelectMethod="GetData"
            EnablePaging="true" StartRowIndexParameterName="iStartRecord" MaximumRowsParameterName="iMaxRecords"
            SortParameterName="sSortColumns" DataObjectTypeName="System.String" TypeName="ListViewTest._Default"
            OldValuesParameterFormatString="original_{0}"></asp:ObjectDataSource>
        <telerik:RadListView runat="server" ID="m_oListView" DataSourceID="m_oDataSource">
            <ItemTemplate>
                <fieldset title="Item">
                    <asp:Label runat="server" Text="Not Selected" />
                </fieldset>
            </ItemTemplate>
            <SelectedItemTemplate>
                <fieldset title="Selected Item">
                    <asp:Label runat="server" Text="Selected" />
                </fieldset>
            </SelectedItemTemplate>
        </telerik:RadListView>
    </asp:Content>

    Default.aspx.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
     
    namespace ListViewTest
    {
        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object senderEventArgs e)
            {
     
            }
     
            public IList<StringGetData(string sSortColumnsint iMaxRecordsint iStartRecord)
            {
                IList<StringoList = new List<String>();
     
                for (int i = 0i < 10i++)
                {
                    oList.Add(i.ToString());
                }
                return oList;
            }
        }
    }

    Site.Master:
    <%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="ListViewTest.SiteMaster" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head runat="server">
        <title></title>
        <link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
        <asp:ContentPlaceHolder ID="HeadContent" runat="server">
        </asp:ContentPlaceHolder>
    </head>
    <body>
        <form runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            <Scripts>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">
                </asp:ScriptReference>
                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">
                </asp:ScriptReference>
            </Scripts>
        </telerik:RadScriptManager>
        <div class="page">
            <div class="header">
                <div class="title">
                    <h1>
                        My ASP.NET Application
                    </h1>
                </div>
                <div class="clear hideSkiplink">
                    <asp:Menu ID="NavigationMenu" runat="server" CssClass="menu" EnableViewState="false" IncludeStyleBlock="false" Orientation="Horizontal">
                        <Items>
                            <asp:MenuItem NavigateUrl="~/Default.aspx" Text="Home"/>
                        </Items>
                    </asp:Menu>
                </div>
            </div>
            <div class="main">
                <asp:ContentPlaceHolder ID="MainContent" runat="server"/>
            </div>
            <div class="clear">
            </div>
        </div>
        <div class="footer">
            
        </div>
        </form>
    </body>
    </html>

    Web.config:
    <?xml version="1.0"?>
     
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
     
    <configuration>
      <appSettings>
        <add key="webpages:Version" value="1.0.0.0" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
        <add key="Telerik.Skin" value="Windows7" />
      </appSettings>
      <connectionStrings>
        <add name="ApplicationServices"
             connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
             providerName="System.Data.SqlClient" />
      </connectionStrings>
     
      <system.web>
        <httpHandlers>
          <remove verb="*" path="*.asmx"/>
          <add verb="*" path="*.asmx"
               type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Culture=neutral, Version=4.0.0.0, PublicKeyToken=31bf3856ad364e35"
               validate="false"/>
          <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" verb="*" validate="false" />
        </httpHandlers>
        <compilation debug="true" targetFramework="4.0" />
     
        <authentication mode="Forms">
          <forms loginUrl="~/Account/Login.aspx" timeout="2880" />
        </authentication>
     
        <membership>
          <providers>
            <clear/>
            <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
                 enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
                 maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
                 applicationName="/" />
          </providers>
        </membership>
     
        <pages>
          <controls>
            <add tagPrefix="ajaxToolkit" namespace="AjaxControlToolkit" assembly="AjaxControlToolkit" />
            <add tagPrefix="telerik" namespace="Telerik.Web.UI" assembly="Telerik.Web.UI" />
            <add tagPrefix="telerik" namespace="Telerik.Charting" assembly="Telerik.Web.UI" />
          </controls>
        </pages>
     
        <profile>
          <providers>
            <clear/>
            <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
          </providers>
        </profile>
     
        <roleManager enabled="false">
          <providers>
            <clear/>
            <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
            <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
          </providers>
        </roleManager>
     
      </system.web>
     
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <add name="Telerik_Web_UI_WebResource_axd"  verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" />
        </handlers>
      </system.webServer>
    </configuration>
  2. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 29 Mar 2012 Link to this post

    Hello Andrey,

    I have assembled a sample project demonstrating the desired functionality. You could achieve your scenario by wrapping the content in the ItemCommand in a LinkButton with CommandName="Select" as it is shown in the example and demo below.
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" CssClass="selectedButtons" runat="server" CommandName="Select">
            <fieldset title="Item">
                <asp:Label ID="Label1" runat="server" Text="Not Selected" />
            </fieldset>
        </asp:LinkButton>
    </ItemTemplate>

    Kind regards,
    Antonio Stoilkov
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Andrey
    Andrey avatar
    18 posts
    Member since:
    Jun 2012

    Posted 30 Mar 2012 Link to this post

    Your example works, thank you!

    However, I was wondering if it was necessary to do a postback every time a new selection occurs. Is there a way to do it all client-side?

    Thank you,
    Andrey
  5. Antonio Stoilkov
    Admin
    Antonio Stoilkov avatar
    530 posts

    Posted 04 Apr 2012 Link to this post

    Hello Andrey,

    The SelectedItemTemplate could be data bound only server side and a request to the server is required. However, in order to improve user experience you could use RadAjax controls to ajaxify the RadListView to enable smoother UI.

    Greetings,
    Antonio Stoilkov
    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.
  6. Andrey
    Andrey avatar
    18 posts
    Member since:
    Jun 2012

    Posted 04 Apr 2012 Link to this post

    Okay, thank you.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017