CodeBehind Can't Get RadListBox CheckBox Checked Item

6 posts, 0 answers
  1. Xibin
    Xibin avatar
    3 posts
    Member since:
    Sep 2011

    Posted 13 Jul 2014 Link to this post

    I Can't Get CheckBox Checked Items, the "MsgList.CheckedItems.Count" Allways Zero. But In my Project another Place Can get it.

    <--This Can't Get.-->
    <telerik:RadNotification runat="server" ID="MessageNotification" AutoCloseDelay="0" Position="BottomRight" OffsetX="-20" OffsetY="-20" LoadContentOn="TimeInterval"
                ContentScrolling="Default" Title="MessageBox" Width="350" EnableRoundedCorners="true" UpdateInterval="10000"
                TitleIcon="~/Common/Images/LogoIcon/logo16.ico" OnCallbackUpdate="MessageNotification_OnCallbackUpdate" OnClientUpdated="OnClientUpdated">
                <ContentTemplate>
                    <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
                        <ContentTemplate>
                            <div style="float: left; margin: 5px">
                                <telerik:RadListBox runat="server" ID="MsgList" Width="340" Height="300" CheckBoxes="True" Culture="zh-CN" DataSourceID="SqlDataSource1">
                                    <ItemTemplate>
                                        <asp:Label runat="server" ID="lbTime" Text='<%# Eval("OptionDateTime") %>'></asp:Label>
                                        <asp:Label runat="server" ID="lbDept" Text='<%# Eval("DepartmentName") %>'></asp:Label>
                                        <asp:Label runat="server" ID="lbUser" Font-Bold="True" Text='<%# Eval("RealName") %>'></asp:Label>
                                        <asp:Label runat="server" ID="lbMsg" ForeColor="Red" Text='<%# Eval("MessageText") %>'></asp:Label>
                                    </ItemTemplate>
                                </telerik:RadListBox>
                                <div style="text-align: center;margin-top: 5px">
                                    <telerik:RadButton runat="server" ID="btnSetReaded" Text="SetReaded" OnClick="btnSetReaded_Click"></telerik:RadButton>
                                </div>
                                <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:SMSConnectString %>"></asp:SqlDataSource>
                            </div>
                        </ContentTemplate>
                    </asp:UpdatePanel>
                </ContentTemplate>
            </telerik:RadNotification>


    ​protected void btnSetReaded_Click(object sender, EventArgs e)
            {
                 IList<RadListBoxItem> selItems = MsgList.CheckedItems;
                foreach (RadListBoxItem item in selItems)
                {
                    ........
                }
            }


    <--This Can Get -->
            <div class="col-mid2">
                <div style="font-size: 12px">Select Role:</div>
                <telerik:RadListBox runat="server" ID="lboxRoleID" Width="100%" Height="370" CheckBoxes="True" />
                <br/>
            </div>   
    protected void btnSave_Click(object sender, EventArgs e)
            {
                int roleid = 0;
                IList<RadListBoxItem> collection = lboxRoleID.CheckedItems;
                 foreach (RadListBoxItem item in collection)
                {
                    ........
                }
            }
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jul 2014 in reply to Xibin Link to this post

    Hi Xibin,

    From your code I have noticed that you are not binding the RadListBox properly. Please do the following modification in your code snippet which works fine at my end.

    ASPX:
    <telerik:RadNotification runat="server" ID="MessageNotification" AutoCloseDelay="0"
        Position="BottomRight" OffsetX="-20" OffsetY="-20" LoadContentOn="TimeInterval"
        ContentScrolling="Default" Title="MessageBox" Width="350" EnableRoundedCorners="true"
        UpdateInterval="10000" VisibleOnPageLoad="true">
        <ContentTemplate>
            <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
                <ContentTemplate>
                    <div style="float: left; margin: 5px">
                        <telerik:RadListBox runat="server" ID="MsgList" Width="340" Height="300" CheckBoxes="True" Culture="zh-CN" DataSourceID="SqlDataSource1">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lbTime" Text='<%# Eval("OrderID") %>'></asp:Label>
                                <asp:Label runat="server" ID="lbDept" Text='<%# Eval("CustomerID") %>'></asp:Label>
                                <asp:Label runat="server" ID="lbUser" Font-Bold="True" Text='<%# Eval("EmployeeID") %>'></asp:Label>
                                <asp:Label runat="server" ID="lbMsg" ForeColor="Red" Text='<%# Eval("ShipCity") %>'></asp:Label>
                            </ItemTemplate>
                        </telerik:RadListBox>
                        <div style="text-align: center; margin-top: 5px">
                            <telerik:RadButton runat="server" ID="btnSetReaded" Text="SetReaded" OnClick="btnSetReaded_Click">
                            </telerik:RadButton>
                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [OrderID], [CustomerID], [EmployeeID], [ShipCity], [ShipRegion] FROM [Orders]">
                            </asp:SqlDataSource>
                        </div>
                    </div>
                </ContentTemplate>
            </asp:UpdatePanel>
        </ContentTemplate>
    </telerik:RadNotification>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Xibin
    Xibin avatar
    3 posts
    Member since:
    Sep 2011

    Posted 14 Jul 2014 in reply to Shinu Link to this post

    Hi,Shinu:

    I was Binded the RadListBox Properly in CodeBehind Page_Load(). But I wasn't pasted that Code.
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 14 Jul 2014 in reply to Xibin Link to this post

    Hi Xibin,

    Unfortunately I couldn't replicate the issue at my end. Please provide your full code for further help.

    Thanks,
    Shinu.
  6. Xibin
    Xibin avatar
    3 posts
    Member since:
    Sep 2011

    Posted 18 Jul 2014 in reply to Shinu Link to this post

    Hi Shinu,

    I find RadListBox in Pages can get checkeditems, but put in RadNotification ContentTemplate can't get checkeditems.What is the cause of this ?
  7. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Jul 2014 in reply to Xibin Link to this post

    Hi Xibin,

    Try to bind the RadListBox in Page_Init event rather than Page_Load event as follows.

    C#:
    protected void Page_Init(object sender, EventArgs e)
    {
        MsgList.DataSourceID = "SqlDataSource1";
        MsgList.DataBind();
    }

    Thanks,
    Shinu.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017