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

CodeBehind Can't Get RadListBox CheckBox Checked Item

4 Answers 69 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Xibin
Top achievements
Rank 1
Xibin asked on 13 Jul 2014, 08:20 AM
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)
            {
                ........
            }
        }

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 14 Jul 2014, 05:49 AM
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.
0
Xibin
Top achievements
Rank 1
answered on 14 Jul 2014, 07:49 AM
Hi,Shinu:

I was Binded the RadListBox Properly in CodeBehind Page_Load(). But I wasn't pasted that Code.
0
Xibin
Top achievements
Rank 1
answered on 18 Jul 2014, 07:27 AM
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 ?
0
Shinu
Top achievements
Rank 1
answered on 21 Jul 2014, 12:21 PM
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.
Tags
ListBox
Asked by
Xibin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Xibin
Top achievements
Rank 1
Share this question
or