RadListView - Ajax Problem - ItemCommand Event

4 posts, 0 answers
  1. Ravi
    Ravi avatar
    1 posts
    Member since:
    Jun 2011

    Posted 23 Jun 2011 Link to this post

    Hi,
    I am using RadListView which updates the page content outside the RadListView (on ItemCommand of RadListView)


    <asp:Panel id="PanelToUpdate" runat="server">


    " CONTENT SHOULD COME HERE WHEN LINK BUTTON INSIDE RADLISTVIEW IS CLICKED ('ITEM-COMMAND' EVENT with 'SELECT' COMMAND )    "
            " THIS PANEL SHOULD NOT BE UPDATED WHEN PAGER'S NEXT OR PREVIOUS BUTTON IS CLICKED.


    </asp:Panel>




    <telerik:RadListView ID="rptArticles" AllowPaging="True" runat="server" OnPreRender="rptArticles_PreRender"
        ItemPlaceholderID="ArticlesList" DataKeyNames="ArticleID" 
        OnItemDataBound="rptArticles_ItemDataBound" EnableViewState="true">
        <LayoutTemplate>
                <ul>
                    <asp:Panel ID="ArticlesList" runat="server" />
                </ul>
                <telerik:RadDataPager ID="pgrAudio" runat="server" PagedControlID="rptArticles" PageSize="5">
                    <Fields>
                        <telerik:RadDataPagerButtonField FieldType="Prev" />
                        <telerik:RadDataPagerButtonField FieldType="Next" />
                    </Fields>
                </telerik:RadDataPager>
        </LayoutTemplate>
        <ItemTemplate>
            <li>
                <asp:LinkButton runat="server" ID="lbArticle" runat="server" CommandName="Select" CommandArgument='<% #Eval("ID") %>' CssClass="thumb">
                    <img id="Img1" alt="" runat="server"
                        src='<% #ResolveUrl(Eval("ImageFile").ToString()) + "?width=148&scale=both&height=91&crop=auto" %>' />
                </asp:LinkButton>
                <div class="title">
                    <asp:Literal ID="Literal1" runat="server" Text='<% #Eval("Title") %>' ></asp:Literal>
                </div>
            </li>
        </ItemTemplate>
    </telerik:RadListView>




    On the top of my htmlbody i am defining the radajaxmanager as follows :


    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="rptArticles">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="PanelToUpdate"/>
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>




    The problem I am facing is :
    - When a pager Next or Previous is clicked, it updates my "PanelToUpdate" as well. I want to prevent it to update in that case. It should be updated only when LinkButton is clicked.


    I tried EventName in AjaxSettings of RadAjaxManager as :


            <telerik:AjaxSetting AjaxControlID="rptArticles" EventName="OnItemCommand">
            <telerik:AjaxSetting AjaxControlID="rptArticles" EventName="OnSelectedIndexChanged">


    But it seems that EventName do not worked for me anytime. my Panel is updating on each click, be it on LinkButton inside radListView, or nearby PagerButtons.

    Please help.



    Ravi
  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 28 Jun 2011 Link to this post

    Hello Ravi,

    You properly observed that the EventName property is not working. To overcome the issue and achieve your goal, you can add the setting settings dynamically and the specify the LinkButtons as ajax control initiator for the PanelToUpdate control. Handle the RadListView PreRender event as below:

    protected void rptArticles_PreRender(object sender, EventArgs e)
    {
        foreach(RadListViewItem item in rptArticles.Items)
        {
            LinkButton lnk = item.FindControl("lbArticle") as LinkButton;
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(lnk, PanelToUpdate);
        }
    }


    Give it a try and let me know if this works for you.

    Best wishes,
    Iana
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Siva
    Siva avatar
    25 posts
    Member since:
    May 2012

    Posted 25 Jan 2013 Link to this post

    <telerik:RadAjaxPanel ID="rapEmplment" runat="server" Width="100%"  >
                                    <telerik:RadGrid ID="rgEmployers" runat="server" EnableViewState="false"
                                        AutoGenerateColumns="False" CellSpacing="0" GridLines="None"
                                        ondetailtabledatabind="rgHHMemberEmployers_DetailTableDataBind"
                                        onneeddatasource="rgHHMemberEmployers_NeedDataSource"
                                        onitemdatabound="rgHHMemberEmployers_ItemDataBound"
                                        onitemcommand="rgHHMemberEmployers_ItemCommand"
                                        oninsertcommand="rgHHMemberEmployers_InsertCommand"
                                        onupdatecommand="rgHHMemberEmployers_UpdateCommand"
                                        OnDeleteCommand ="rgHHMemberEmployers_DeleteCommand" 
                                        onprerender="LockDownGridIfEditOrInsert">
                                        <MasterTableView ShowHeadersWhenNoRecords="true" DataKeyNames="IncomeId" HierarchyLoadMode="ServerBind" Width="100%" CommandItemDisplay="Top" cl>
                                            <DetailTables>
                                                <telerik:GridTableView runat="server" Name="PayDates" Width="100%" DataKeyNames="EmploymentId"
                                                    CommandItemDisplay="Bottom">
                                                    <CommandItemTemplate>
                                                        <Bad:BadLabel ID="blWageFooter" runat="server" Text="" ViewStateMode="Disabled"></Bad:BadLabel>
                                                    </CommandItemTemplate>
                                                    <CommandItemStyle HorizontalAlign="Center" />
                                                    <CommandItemSettings ExportToPdfText="Export to PDF" />
                                                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                                                    </RowIndicatorColumn>
                                                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                                                    </ExpandCollapseColumn>
                                                    <Columns>
                                                        ----
                                                       ------
                                                           
                                                         ---
                                                    </Columns>
                                                    <EditFormSettings>
                                                        <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                                        </EditColumn>
                                                    </EditFormSettings>
                                                </telerik:GridTableView>
                                            </DetailTables>
                                            <CommandItemSettings ExportToPdfText="Export to PDF" ShowRefreshButton="false" AddNewRecordText="Add New Employment..." />
                                            <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                                            </RowIndicatorColumn>
                                            <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"
                                                Visible="True">
                                            </ExpandCollapseColumn>
                                            <Columns>
     
                                                        ----
                                                       ------
                                                           
                                                         ---
                                                 
                                            </Columns>
                                            <EditFormSettings EditFormType="Template">
                                                <FormTemplate>
                                                    <table id="EditEmp" style="border-collapse: collapse; background: white; width:100%; border:0; padding:1; border-spacing:2; " >
                                                        <tr class="EditFormHeader">
                                                            <td colspan="4" style="font-size: small">
                                                                <b>Employment Details:</b></td>
                                                        </tr>
                                                        <tr>
                                                            <td colspan="4">
                                                                <telerik:RadTextBox ID="txtEditEmpName" runat="server" Label="Employer Name:"
                                                                    Text='<%# Bind("EmpName") %>' Width="300px" MaxLength="100">
                                                                </telerik:RadTextBox>
                                                                <asp:RequiredFieldValidator ID="rfvEditEmpName" runat="server" ControlToValidate="txtEditEmployerName" ValidationGroup="UpdateEmployment" ErrorMessage="*" Text="*"></asp:RequiredFieldValidator>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                <Bad:BadLabel ID="BadLabel1" runat="server" Text="Start Date:" ViewStateMode="Disabled"></Bad:BadLabel>
                                                            </td>
                                                            <td>
                                                                <telerik:RadDatePicker ID="rdpEditEmpStDate" runat="server" ZIndex="100001">
                                                                </telerik:RadDatePicker>
                                                            </td>
                                                            <td>
                                                                <Bad:BadLabel ID="blEditBudDt" runat="server" Text="Budgeted Date:" ViewStateMode="Disabled"></Bad:BadLabel>
                                                            </td>
                                                            <td>
                                                                <telerik:RadDatePicker ID="rdpEditEmpEditBudDt" runat="server" ZIndex="100001">
                                                                </telerik:RadDatePicker>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                <Bad:BadLabel ID="BadLabel2" runat="server" Text="RepordDt" ViewStateMode="Disabled"></Bad:BadLabel>
                                                            </td>
                                                            <td>
                                                                <telerik:RadDatePicker ID="rdpEditEmp RepordDt " runat="server" ZIndex="100001">
                                                                </telerik:RadDatePicker>
                                                            </td>
                                                            <td>
                                                                <Bad:BadLabel ID="BadLabel3" runat="server" Text="Effective Date:" ViewStateMode="Disabled"></Bad:BadLabel>
                                                            </td>
                                                            <td>
                                                                <telerik:RadDatePicker ID="rdpEditEmpEffDt" runat="server" ZIndex="100001">
                                                                </telerik:RadDatePicker>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                <Bad:BadLabel ID="BadLabel4" runat="server" Text="Frequency:" ViewStateMode="Disabled"></Bad:BadLabel>
                                                            </td>
                                                            <td>
                                                                <telerik:RadComboBox OnClientDropDownClosed="dropDownClosed" ID="rcbEditEmpFrequency" runat="server" style="z-index: 100001;">
                                                                </telerik:RadComboBox>
                                                                <asp:RequiredFieldValidator ID="rfvuEditEmpFreq" runat="server" ControlToValidate="rcbEditEmpFreq" ValidationGroup="UpdateEmployment" ErrorMessage="*" Text="*"></asp:RequiredFieldValidator>
                                                            </td>
                                                            <td>
                                                                <Bad:BadLabel ID="BadLabel6" runat="server" Text="Hours Worked:" ViewStateMode="Disabled"></Bad:BadLabel>
                                                            </td>
                                                            <td>
                                                                <telerik:RadComboBox OnClientDropDownClosed="dropDownClosed" ID="rcbEditEmpHrsWrkd" runat="server" style="z-index: 100001;">
                                                                </telerik:RadComboBox>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td>
                                                                <Bad:BadLabel ID="BadLabel5" runat="server" Text="Verification:" ViewStateMode="Disabled"></Bad:BadLabel>
                                                            </td>
                                                            <td colspan="3">
                                                                <telerik:RadComboBox OnClientDropDownClosed="dropDownClosed" ID="rcbEditEmpVerification" runat="server" Width="300px" style="z-index: 100001;">
                                                                </telerik:RadComboBox>
                                                            </td>
                                                        </tr>
                                                        <tr class="EditFormHeader">
                                                            <td colspan="2" style="font-size: small">
                                                                <b>Wages:</b></td>
                                                        </tr>
                                                        <tr>
                                                            <td colspan="4">                                                 
                                                                <telerik:RadListView ID="rlvEmpWag" runat="server"
                                                                    InsertItemPosition="LastItem"
                                                                    onneeddatasource=" rlvEmpWag _NeedDataSource"
                                                                    onitemcommand=" rlvEmpWag _ItemCommand"
                                                                    DataKeyNames="WageId">
                                                                    <LayoutTemplate>
                                                                        <asp:PlaceHolder runat="server" ID="itemPlaceholder"></asp:PlaceHolder>
                                                                        <telerik:RadButton ID="btnAddWage" runat="server" ButtonType="LinkButton"
                                                                            CommandName="InitInsert" Text='Add Wage'>
                                                                        </telerik:RadButton>
                                                                    </LayoutTemplate>
                                                                    <ItemTemplate>
                                                                        <table>
                                                                            <tr>
                                                                                <td>
                                                                                    <Bad:BadLabel ID="BadLabel29" runat="server" Text="Pay Date:" ViewStateMode="Disabled"></Bad:BadLabel
                                                                                    <Bad:BadLabel ID="blEditEmpdt" runat="server" Text='<%# Bind("PayDate", "{0:MM/dd/yyyy}") %>' ViewStateMode="Disabled"></Bad:BadLabel>
                                                                                       
                                                                                </td>                                                                           
                                                                                <td>
                                                                                    <Bad:BadLabel ID="BadLabel28" runat="server" Text="Amount:" ViewStateMode="Disabled"></Bad:BadLabel
                                                                                    <Bad:BadLabel ID="blAmt" runat="server" Text='<%# Bind("Amount","{0:c}") %>' ViewStateMode="Disabled"></Bad:BadLabel>
                                                                                                                                                                   
                                                                                </td>
                                                                                <td>
                                                                                    <telerik:RadButton ID="btnWag" runat="server" ButtonType="StandardButton" Icon-PrimaryIconCssClass="rbEdit" Width="20px"
                                                                                         CausesValidation="false" CommandName="Edit" ToolTip="Edit">
                                                                                    </telerik:RadButton>
                                                                                </td>
                                                                                <td>
                                                                                    <telerik:RadButton ID="btnDelWag" runat="server" ButtonType="StandardButton" Icon-PrimaryIconCssClass="rbRemove" Width="20px"
                                                                                         CausesValidation="false" CommandName="Delete" ToolTip="Delete">
                                                                                    </telerik:RadButton>
                                                                                </td>
                                                                            </tr>
                                                                        </table>
                                                                    </ItemTemplate>
                                                                    <EditItemTemplate>
                                                                    <table>
                                                                        <tr>
                                                                            <td><Bad:BadLabel ID="BadLabel28" runat="server" Text="Pay Date:" ViewStateMode="Disabled"></Bad:BadLabel>
                                                                            <telerik:RadDatePicker ID="rdpEditEmpWageDate" runat="server" ZIndex="100001" SelectedDate='<%# Bind("PayDate") %>'>
                                                                                            </telerik:RadDatePicker>
                                                                            <asp:RequiredFieldValidator ID="rfvuEditEmpWagDt" runat="server" ControlToValidate="rdpEditEmpWageDate" ValidationGroup="UpdateEmployment" ErrorMessage="*" Text="*"></asp:RequiredFieldValidator>
                                                                            </td>
                                                                            <td>
                                                                            <telerik:RadNumericTextBox ID="txtEditEmpPayAmt" runat="server" Label="Amount:" DataFormatString="{0:$###,###}"
                                                                                                 NumberFormat-DecimalDigits="0" Type="Currency" MaxLength="9" Text ='<%# Bind("PaymentAmount") %>'>
                                                                                            </telerik:RadNumericTextBox>
                                                                             <asp:RequiredFieldValidator ID="rfvuEditEmpWageAmt" runat="server" ControlToValidate="txtEditEmpPayAmt" ValidationGroup="UpdateEmployment" ErrorMessage="*" Text="*"></asp:RequiredFieldValidator>
                                                                            </td>
                                                                            <td>                                                                           
                                                                                <telerik:RadButton ID="btnInsertWage" runat="server" ButtonType="StandardButton" Icon-PrimaryIconCssClass="rbSave" Width="20px"
                                                                                    CommandName="Update" ToolTip="Update" ValidationGroup="NewWage">
                                                                                </telerik:RadButton>
                                                                                  
                                                                                <telerik:RadButton ID="btnCancelWage" runat="server" ButtonType="StandardButton" Icon-PrimaryIconCssClass="rbRemove" Width="20px"
                                                                                    CausesValidation="False" CommandName="Cancel" ToolTip="Cancel">
                                                                                </telerik:RadButton>                                                                                                  
                                                                            </td>
                                                                         </tr>
                                                                     </table>
                                                                    </EditItemTemplate>
                                                                    <InsertItemTemplate>
                                                                        <table>
                                                                            <tr>
                                                                                <td>
                                                                                    <Bad:BadLabel ID="blInsertEmpWageDt" runat="server" Text="Pay Date:" ViewStateMode="Disabled"></Bad:BadLabel>
                                                                                </td>
                                                                                <td>
                                                                                    <telerik:RadDatePicker ID="rdpInsertEmpWageDt" runat="server" ZIndex="100001">
                                                                                    </telerik:RadDatePicker>
                                                                                    <asp:RequiredFieldValidator ID="rfvInsertEmpWageDate" runat="server" ControlToValidate=" rdpInsertEmpWageDt " ValidationGroup="NewWage" ErrorMessage="*" Text="*"></asp:RequiredFieldValidator>
                                                                                </td>
                                                                                <td>
                                                                                    <telerik:RadNumericTextBox ID="txtInsertAmt" runat="server" Label="Amount:"
                                                                                        NumberFormat-DecimalDigits="2" Type="Currency" MaxLength="9">
                                                                                    </telerik:RadNumericTextBox>                                                                               
                                                                                    <asp:RequiredFieldValidator ID="rfvInsertEmpPayAmt" runat="server" ControlToValidate=" txtInsertAmt " ValidationGroup="NewWage" ErrorMessage="*" Text="*"></asp:RequiredFieldValidator>
                                                                                </td>
                                                                                <td>                                                                               
                                                                                    <telerik:RadButton ID="btnInsertWage" runat="server" ButtonType="StandardButton" Icon-PrimaryIconCssClass="rbSave" Width="20px"
                                                                                        CommandName="PerformInsert" ToolTip="Insert" ValidationGroup="NewWage" AutoPostBack="true" CausesValidation="true">
                                                                                    </telerik:RadButton>
                                                                                      
                                                                                    <telerik:RadButton ID="btnCancelWage" runat="server" ButtonType="StandardButton" Icon-PrimaryIconCssClass="rbRemove" Width="20px"
                                                                                        CausesValidation="False" CommandName="Cancel" ToolTip="Cancel">
                                                                                    </telerik:RadButton>                                                                                                  
                                                                                </td>
                                                                            </tr>
                                                                        </table>
                                                                    </InsertItemTemplate>           
                                                                </telerik:RadListView>
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td style="text-align:right" colspan="4">
                                                                <telerik:RadButton ID="btnUpdate" runat="server" ButtonType="LinkButton" ValidationGroup="UpdateEmployment"
                                                                    CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
                                                                    Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'>
                                                                </telerik:RadButton>
                                                                  
                                                                <telerik:RadButton ID="btnCancel" runat="server" ButtonType="LinkButton"
                                                                    CausesValidation="False" CommandName="Cancel" Text="Cancel">
                                                                </telerik:RadButton>
                                                            </td>
                                                        </tr>
                                                    </table>
                                                </FormTemplate>
                                        </EditFormSettings>
                                        </MasterTableView>
                                        <FilterMenu EnableImageSprites="False">
                                        </FilterMenu>
                                        <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
                                        </HeaderContextMenu>
                                    </telerik:RadGrid>
                                </telerik:RadAjaxPanel>


    when click the "btnAddwage" button , listview controls are open for adding the values, this time calls the itemcommand event properly but  then after adding values if i click the  click the "btnInsertWage" button for save the values this time itemcommand does'nt call ,
    in my itemcommand even i wrote the code for inserting the data into list view
    code behind code
     
     protected void rlvEditEmpWages_ItemCommand(object sender, RadListViewCommandEventArgs e)
            {
                if (e.CommandName == RadListView.InitInsertCommandName || e.CommandName == RadListView.EditCommandName)
                {
                    ((RadListView)sender).FindControl("btnAddWage").Visible = false;
                }
                else if (e.CommandName == RadListView.CancelCommandName)
                {
                    ((RadListView)sender).FindControl("btnAddWage").Visible = true;
                }
                else if (e.CommandName == RadListView.PerformInsertCommandName)
                {
                    RadDatePicker rdpPayDate = ((RadDatePicker)e.ListViewItem.FindControl("rdpInsertEmpWageDate"));
                    RadNumericTextBox rntbPayAmt = ((RadNumericTextBox)e.ListViewItem.FindControl("txtInsertEmpPayAmt"));
     
                    if (rdpPayDate.SelectedDate.HasValue && rntbPayAmt.Value.HasValue)
                    {
                        WageDTO newWage = new WageDTO();
                        newWage.PayDate = ((RadDatePicker)e.ListViewItem.FindControl("rdpInsertEmpWageDate")).SelectedDate;
                        newWage.PaymentAmount = (Decimal?)((RadNumericTextBox)e.ListViewItem.FindControl("txtInsertEmpPayAmt")).Value;
                        newWage.CreatedBy = CurrentUser;
                        List<WageDTO> wages = ((EmploymentIncomeDTO)ReviewCase.Households.Find(hh => hh.ReviewRecordType == _currentRecordType).Members.Find(member => member.PersonId == _currentMemberDetailId).Income.Find(income => income.IncomeId == _currentMemberEmploymentIncomeId)).Wages;
                        newWage.WageId = 0 - (wages.Count(wage => wage.WageId <= 0) + 1);
                        wages.Add(newWage);
     
                        ((RadListView)sender).FindControl("btnAddWage").Visible = true;
                        ((RadListView)sender).DataSource = null;
                        ((RadListView)sender).Rebind();
                    }
                }

    plzz help me im struck here from past 2 days
  5. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 30 Jan 2013 Link to this post

    Hi Siva,

    I reviewed the provided code and noticed that the "btnInsertWage" button does not have any CommandName set so it does not fire any command to enter in the ItemCommand event. please set this property for the button and verify how it goes.

    Kind regards,
    Maria Ilieva
    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.
Back to Top