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

RadListView Ajax Button not Working When Filtered by RadComboBox

1 Answer 86 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 02 Dec 2012, 08:25 PM
hello
i have 4 main control, a radcombobox, radlistview with a asp button, and a label, i want to filter radlistview data by radcombobox selected value,( i do it without  problem), and after click on asp button in radlistview, that return datakey with button commandargument value to label, but my problem is after click on asp button, label show nothing.
RadComboBox code:
aspx:
<telerik:RadComboBox ID="CityDDL" runat="server"
     AutoPostBack="true" Label="City :" Skin="Default" />
cs:
protected void LoadCities()
{
    SqlConnection connection = new SqlConnection(
    ConfigurationManager.ConnectionStrings["SiteSqlServer1"].ConnectionString);
     SqlDataAdapter adapter = new SqlDataAdapter(@"", connection);
    DataTable dt = new DataTable();
    adapter.Fill(dt);
     CityDDL.DataTextField = "Name";
    CityDDL.DataValueField = "ID";
    CityDDL.DataSource = dt;
    CityDDL.DataBind();
    // Insert the first item.
    CityDDL.Items.Insert(0, new RadComboBoxItem("- Select City -"));
}

RadListView Code:
aspx:
<telerik:RadListView ID="RadListView1" runat="server" DataSourceID="SqlDataSource1"
    ItemPlaceholderID="ListViewContainer" AllowPaging="True" PageSize="12"
        onprerender="RadListView1_PreRender">
    <LayoutTemplate>                    
               <asp:PlaceHolder runat="server" id="ListViewContainer" />
    </LayoutTemplate>
    <ItemTemplate>
        <fieldset style="float: left; width: 266px; height: 260px;">
            <legend><b>State Name:</b>: <%#Eval("Name")%></legend>
            <div class="details">                           
                            <asp:Button ID="SelectStateID" OnClick="SelectStateID_Click"
CommandArgument='<%# Eval("ID") %>' runat="server" Text="Select State"  />
                <div class="data-container">
                    <ul>
                        <li>
                            <label>
                                State Code:
                            <%#Eval("Code")%>                          
                        </li>                       
                    </ul>                                        
                </div>
            </div>
        </fieldset>
    </ItemTemplate>
</telerik:RadListView>

cs:
protected void RadListView1_PreRender(object sender, EventArgs e)
{
    foreach (RadListViewItem item in RadListView1.Items)
    {
        Button lnk = item.FindControl("SelectStateID") as Button;
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(lnk, Label1);
    }
}

ASP Button Code:
cs:
protected void SelectStateID_Click(object sender, EventArgs e)
{   
    var argument = ((Button)sender).CommandArgument;
    Label1.Text = argument.ToString();
}

RadAjaxManager Code:
aspx:
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
         <AjaxSettings>
             <telerik:AjaxSetting AjaxControlID="CityDDL" EventName="SelectedIndexChanged">
                 <UpdatedControls>
                     <telerik:AjaxUpdatedControl ControlID="RadListView1" />
                 </UpdatedControls>
             </telerik:AjaxSetting>
         <telerik:AjaxSetting AjaxControlID="SelectStateID" EventName="SelectStateID_Click">
                 <UpdatedControls>
                     <telerik:AjaxUpdatedControl ControlID="Label1" />                                       
                 </UpdatedControls>
             </telerik:AjaxSetting>
        </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
            <asp:Image ID="Image1" runat="server" ImageUrl="~/images/WebResource.axd.gif" AlternateText="Loading..." />
        </telerik:RadAjaxLoadingPanel>

ASP Label:
aspx:
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

please help me.
thanks

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 06 Dec 2012, 06:41 AM
Hello,

The problem you are observing is caused by the fact that you are adding the Ajax settings too late in the page life-cycle and the RadAjaxManager could not register them.

If the Label1 control is located directly on the page you could achieve your goal by using the following Ajax settings set declaratively in mark-up:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" DefaultLoadingPanelID="RadAjaxLoadingPanel1">
     <AjaxSettings>
         <telerik:AjaxSetting AjaxControlID="CityDDL" EventName="SelectedIndexChanged">
             <UpdatedControls>
                 <telerik:AjaxUpdatedControl ControlID="RadListView1" />
             </UpdatedControls>
         </telerik:AjaxSetting>
     <telerik:AjaxSetting AjaxControlID="SelectStateID" EventName="SelectStateID_Click">
             <UpdatedControls>
                 <telerik:AjaxUpdatedControl ControlID="Label1" />                                      
             </UpdatedControls>
         </telerik:AjaxSetting>
         <telerik:AjaxSetting AjaxControlID="RadListView1">
             <UpdatedControls>
                 <telerik:AjaxUpdatedControl ControlID="Label1" /> 
                 <telerik:AjaxUpdatedControl ControlID="RadListView1" />                
             </UpdatedControls>
         </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

If the label is located somewhere else please elaborate a bit more.

Regards,
Andrey
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.
Tags
ListView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or