Problem transferring between 2 databind Listboxes

3 posts, 0 answers
  1. Sunil
    Sunil avatar
    29 posts
    Member since:
    Jul 2010

    Posted 15 Apr 2011 Link to this post

    Hi all,

    I have two RadListBox(s) that transfer to each other. Both are populated using <ItemTemplate> and DataBind() with database data from code behind.

    When I transfer one item to another, the row appears in the respective RadListBox but it does not show data. I've attached a picture with a side by side before and after.

    Can anyone let me know what I'm doing wrong?

    Code as below

    <telerik:RadPageView ID="RadPageView_Visitor_Authentication" runat="server">
                     
                <br />
     
                <asp:Table runat="server" CssClass="form_table">
     
     
                    <asp:TableRow runat="Server">
                             
                        <asp:TableCell runat="server" CssClass="form_label_center">
                            <asp:Label ID="Label_Available_Terminals" runat="server" Text="Available Terminals:"
                            CssClass="form_span"></asp:Label>
                        </asp:TableCell>
     
                    </asp:TableRow>
     
                    <asp:TableRow runat="Server">
     
                        <asp:TableCell runat="server" CssClass="form_label_center">
                            <telerik:RadListBox runat="server" ID="RadListBox_Available_Terminals" Height="150px" Width="300px"
                            AllowTransfer="true" TransferToID="RadListBox_Authenticate_Terminals"
                            OnTransferring="Authenticating_Terminals_Transferring"
                            AutoPostBackOnTransfer="true">
                                 
                                <HeaderTemplate>
                                    <table width="100%">
                                        <tr>
                                            <td width="20%">
                                                <asp:Label ID="Label7" runat="server" Text="Admin"></asp:Label>
                                            </td>
                                            <td width="80%">
                                                <div align="left">
                                                    <asp:Label ID="Label8" runat="server" Text="Terminal - Location"></asp:Label>
                                                </div>
                                            </td>
                                        </tr>
                                    </table>
                                </HeaderTemplate>
     
     
     
                                <ItemTemplate>
     
                                <table width="100%">
                                    <tr>
                                        <td width="20%">
                                            <asp:CheckBox runat="server" ID="chk_admin" Checked="false"
                                             Enabled="false"/>
                                        </td>
                                        <td width="80%">
                                            <div align="left">
                                                <asp:Label runat="server" ID="Label_Terminal_Details_1">
                                                    <%# DataBinder.Eval(Container, "Attributes['Terminal_String']") %>
                                                </asp:Label>
     
                                                <asp:Label runat="server" ID="Label_Terminal_Nitgen_ID_1" Visible="false">
                                                    <%# DataBinder.Eval(Container, "Attributes['Terminal_Nitgen_ID']")%>
                                                </asp:Label>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                             
                            </ItemTemplate>
     
                            <FooterTemplate>
                            <br />
                            </FooterTemplate>
     
                                <ButtonSettings Position="Bottom" HorizontalAlign="Center"/>
                            </telerik:RadListBox>
                        </asp:TableCell>
     
                    </asp:TableRow>
     
     
                    <asp:TableRow runat="Server">
     
                        <asp:TableCell runat="server" CssClass="form_td_center">
     
                            <span class="form_span">
                                <asp:Literal ID="Literal_Visitor_Name_Terminal" runat="server"></asp:Literal>
                             
                                <asp:Label ID="Label_Authentication_On" runat="server" Text=" Can Authenticate On:"></asp:Label>
                            </span>
     
                        </asp:TableCell>
     
                    </asp:TableRow>
     
     
                    <asp:TableRow runat="Server">
     
                        <asp:TableCell runat="server" CssClass="form_td_center">
                            <telerik:RadListBox runat="server" ID="RadListBox_Authenticate_Terminals" Height="120px" Width="300px">
                            <HeaderTemplate>
                                <table width="100%">
                                    <tr>
                                        <td width="20%">
                                            <asp:Label ID="Label1" runat="server" Text="Admin"></asp:Label>
                                        </td>
                                        <td width="80%">
                                            <div align="left">
                                                <asp:Label ID="Label2" runat="server" Text="Terminal - Location"></asp:Label>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </HeaderTemplate>
     
                            <ItemTemplate>
     
                                <table width="100%">
                                    <tr>
                                        <td width="20%">
                                            <asp:CheckBox runat="server" ID="chk_admin" Checked="false"
                                             OnCheckedChanged="User_Terminal_Admin_check_changed"
                                             AutoPostBack="True" />
                                        </td>
                                        <td width="80%">
                                            <div align="left">
                                                <asp:Label runat="server" ID="Label_Terminal_Details">
                                                    <%# DataBinder.Eval(Container, "Attributes['Terminal_String']") %>
                                                </asp:Label>
     
                                                <asp:Label runat="server" ID="Label_Terminal_Nitgen_ID" Visible="false">
                                                    <%# DataBinder.Eval(Container, "Attributes['Terminal_Nitgen_ID']")%>
                                                </asp:Label>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                             
                            </ItemTemplate>
     
                            </telerik:RadListBox>  
                        </asp:TableCell>
     
                    </asp:TableRow>
     
                </asp:Table>
                 
                 
         
                     
     
            </telerik:RadPageView>



    Code Behind:

    //Get All Terminals
                    TD_Cmd = TDConnection.CreateCommand();
                    TD_Cmd.CommandText = "EXECUTE " + SQL_Customer_Connection.Product_Name + "_sp_Terminal_List " +
                        "@Param_Customer_ID_Ref = @Param_Customer_ID_Ref1, " +
                        "@Param_Company_ID_Ref = @Param_Company_ID_Ref1";
     
                    TD_Cmd.Parameters.Add(new SqlParameter("@Param_Customer_ID_Ref1",
                        (string)HttpContext.Current.Session["User_Belongs_To_Customer_Ref_ID"]));
                    TD_Cmd.Parameters.Add(new SqlParameter("@Param_Company_ID_Ref1",
                        (string)HttpContext.Current.Session["User_Belongs_To_Company_Ref_ID"]));
     
                    TD_DR = TD_Cmd.ExecuteReader();
     
     
                    while (TD_DR.Read())
                    {
                        RadListBoxItem new_item = new RadListBoxItem();
     
                        new_item.Attributes.Add("Terminal_String",
                            (string)TD_DR["Terminal_Name"] + " - " + (string)TD_DR["Terminal_Location"]);
                        new_item.Attributes.Add("Terminal_Nitgen_ID", (Convert.ToInt32(TD_DR["Nitgen_Terminal_ID_Ref"])).ToString());
     
                        RadListBox_Available_Terminals.Items.Add(new_item);
                        RadListBox_Available_Terminals.DataBind();
     
                    }
     
     
                    TD_DR.Close();
     
     
                    //Get List of Terminals that this visitor can authenticate on
                    TD_Cmd = TDConnection.CreateCommand();
                    TD_Cmd.CommandText = "EXECUTE " + SQL_Customer_Connection.Product_Name + "_sp_Terminal_User_Authentication_List " +
                        "@Param_Customer_ID_Ref = @Param_Customer_ID_Ref1, " +
                        "@Param_Company_ID_Ref = @Param_Company_ID_Ref1, " +
                        "@Param_User_ID = @Param_User_ID1";
     
                    TD_Cmd.Parameters.Add(new SqlParameter("@Param_Customer_ID_Ref1",
                        (string)HttpContext.Current.Session["User_Belongs_To_Customer_Ref_ID"]));
                    TD_Cmd.Parameters.Add(new SqlParameter("@Param_Company_ID_Ref1",
                        (string)HttpContext.Current.Session["User_Belongs_To_Company_Ref_ID"]));
                    TD_Cmd.Parameters.Add(new SqlParameter("@Param_User_ID1",
                        Label_Visitor_ID1.Text));
     
                    TD_DR = TD_Cmd.ExecuteReader();
     
                    while (TD_DR.Read())
                    {
                        RadListBoxItem new_item = new RadListBoxItem();
                        new_item.Attributes.Add("Terminal_String",
                            (string)TD_DR["Terminal_Name"] + " - " + (string)TD_DR["Terminal_Location"]);
                        new_item.Attributes.Add("Terminal_Nitgen_ID", (Convert.ToInt32(TD_DR["Nitgen_Terminal_ID_Ref"])).ToString());
     
                        RadListBox_Authenticate_Terminals.Items.Add(new_item);
                        RadListBox_Authenticate_Terminals.DataBind();
     
                        if (Convert.ToInt32(TD_DR["User_Priv"].ToString()) == 1)
                        {
                            //Master User
                            CheckBox current_checkbox = new_item.FindControl("chk_admin") as CheckBox;
                            current_checkbox.Checked = true;
                        }
                    }
     
                    RadListBox_Authenticate_Terminals.DataBind();
     
     
     
    ...........
  2. Sunil
    Sunil avatar
    29 posts
    Member since:
    Jul 2010

    Posted 15 Apr 2011 Link to this post

    I was able to modify the code for the ontransferring event which proved successful.

    Still, I wouldn't mind the "real" solution from telerik.

    public void Authenticating_Terminals_Transferring(object sender, RadListBoxTransferringEventArgs e)
            {
                //ScriptManager.RegisterStartupScript(Page, Page.GetType(), "RT_Visiw235erertble", "alert('Display Terminal');", true);
     
                e.Cancel = true;
     
                //Adding User to Terminal
                if (e.SourceListBox.ID == "RadListBox_Available_Terminals")
                {
              
                    foreach (RadListBoxItem item in e.Items)
                    {
     
                        RadListBoxItem new_item = new RadListBoxItem();
                        new_item.Attributes.Add("Terminal_String", item.Attributes["Terminal_String"]);
                        new_item.Attributes.Add("Terminal_Nitgen_ID", item.Attributes["Terminal_Nitgen_ID"]);
                        new_item.DataBind();
     
                        e.DestinationListBox.Items.Add(new_item);
                        e.DestinationListBox.DataBind();
                        e.SourceListBox.Items.Remove(item);
                        e.SourceListBox.DataBind();
     
                        //2 = Normal User
                    }   
                }
                //Removing user from Terminal
                else if (e.SourceListBox.ID == "RadListBox_Authenticate_Terminals")
                {
                     
                    foreach (RadListBoxItem item in e.Items)
                    {
                        RadListBoxItem new_item = new RadListBoxItem();
                        new_item.Attributes.Add("Terminal_String", item.Attributes["Terminal_String"]);
                        new_item.Attributes.Add("Terminal_Nitgen_ID", item.Attributes["Terminal_Nitgen_ID"]);
                        new_item.DataBind();
     
                        e.DestinationListBox.Items.Add(new_item);
                        e.DestinationListBox.DataBind();
                        e.SourceListBox.Items.Remove(item);
                        e.SourceListBox.DataBind();
     
                    }
                }
       
            }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Dimitar Terziev
    Admin
    Dimitar Terziev avatar
    1266 posts

    Posted 20 Apr 2011 Link to this post

    Hi Sunil,

    When you transfer templated items with binding expressions, in order to have these expressions evaluated after the items are transferred, you should subscribe to the Transferred server-side event and call databind method for each of the transferred items.

    You could check this demo as it's demonstrating such a scenario.

    Best wishes,
    Dimitar Terziev
    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.

Back to Top