0

1.)我正在使用下面的代码将项目从一个转移RadListBox到另一个。

HTML 代码:

A<telerik:RadListBox ID="RadListBox1" runat="server" Width="250px" Height="200px" 
 TransferMode="Move" AllowTransfer="True" TransferToID="rlbGI_BU" SelectionMode="Multiple"
 OnTransferred="RadListBox1_Transferred" 
 AutoPostBackOnTransfer="true">
</telerik:RadListBox>
B<telerik:RadListBox ID="RadListBox2" runat="server" Width="250px" Height="200px"
 EnableEmbeddedSkins="False" Skin="MetroRed" ImagesPath="../App_Themes/MetroRed/ListBox"
 OnInserted="RadListBox2_Inserted" SelectionMode="Multiple"
 OnDeleted="RadListBox2_Deleted" AutoPostBackOnDelete="true">
</telerik:RadListBox>
<br />
<asp:Label runat="server" ID="lblDeletedList2"></asp:Label> &nbsp; &nbsp;
<asp:Label runat="server" ID="lblInsertedList2"></asp:Label> &nbsp; &nbsp;
<asp:Label runat="server" ID="lblTransdList1"></asp:Label> &nbsp; &nbsp;

C#代码:

private string _SPID = null;
private DataTable _dtSPBU = null;

protected void Page_Load(object sender, EventArgs e)
{
    _SPID = Request.QueryString["SPID"];
    if (!string.IsNullOrEmpty(_SPID))
    {
        _dtSPBU = SDM.SPBU.GetSPBUBySPBUfoSPID(_SPID);
    }
}

protected void bind_RadListBox1()
{
    RadListBox1.DataTextField = "BUName";
    RadListBox1.DataValueField = "SPBUfoBUID";
    RadListBox1.DataSource = _dtSPBU;
    RadListBox1.DataBind();
}

protected void RadListBox2_Inserted(object sender, RadListBoxEventArgs e)
{
    ArrayList myTest = new ArrayList();
    //StringBuilder s = new StringBuilder();
    for (int i = 0; i < e.Items.Count; i++)
    {
        myTest.Add(rlbGI_BU.Items[i].Text);

        foreach (string x in myTest)
        {
                lblInsertedList2.Text += x + ", " + "&nbsp;";
        }
    } 
}

protected void RadListBox2_Deleted(object sender, RadListBoxEventArgs e)
{
    lblDeletedList2.Text += e.Items.Count.ToString() + " items are deleted";
}

protected void RadListBox1_Transferred(object sender, RadListBoxTransferredEventArgs e)
{       
    lblTransdList1.Text += e.Items.Count.ToString() + " items are transferred";
}

我想将传输的项目从一个控件(比如标签)中获取,因为稍后我必须根据 RadListBox2 中的项目绑定RadListBox1一个。 为此,我创建了事件,我试图在其中获取标签中的项目。 现在,当我将 RadListBox1 的 1 项以上传输到 RadListBox2 时(使用 ctrl 按钮),则重复第一个选定项。RadListBox2LabellblInsertedList2RadGrid
RadListBox2_InsertedRadListBox2

示例: RadListBox1 有 "a","b","c" 项。当我将所有“a”、“b”、“c”一起从 RadListBox1 传输到 RadListBox2 时(使用 ctrl 按钮)

我看到以下输出: aababc

正确的输出应该是:abc

请检查以下快照以了解上述问题: 在此处输入图像描述 再次,当我将项目 1 一个地从 RadListBox1 传输到 RadListBox2 时,RadListBox1 具有“a”、“b”、“c”项目

示例: 当我只传输a时,我看到下面的输出:a(第一次)当我只传输b时,我看到下面的输出:a,a(第二次)当我只传输c时,我看到下面的输出:a,a , a (第三次)

请检查以下快照以了解上述问题: 2.)我想绑定一个使用:在此处输入图像描述
RadGrid

  • _SPID = Request.QueryString["SPID"]
  • 进入 RadListBox2 的项目(仅从 RadListBox1 中选择的项目)

现在我RadGrid只使用绑定Request.QueryString["SPID"],所以我得到了与“SPID”相关的所有数据

例子:

SPID RadListBox1_Items 值

014 a 测试1

014 b测试2 014

c 测试3

我的要求是:如果假设RadListBox2只有 2 个项目 "a" , "c" 则数据RadGrid应基于 RadListBox2 项目和 "SPID" 绑定

SPID RadListBox2_Items 值

014 测试1

014 测试3

我希望我把我的要求说清楚了。如果有任何混淆,请告诉我。请回答这两点。
提前致谢。

4

1 回答 1

0

我认为下面的代码将满足您的要求

protected void RadListBox2_Inserted(object sender, RadListBoxEventArgs e)
{
    ArrayList myTest = new ArrayList();
    //StringBuilder s = new StringBuilder();
    for (int i = 0; i < e.Items.Count; i++)
    {
        myTest.Add(e.Items[i].Text);    

    } 
     foreach (string x in myTest)
        {
                lblInsertedList2.Text += x + ", " + "&nbsp;";
        }
}

或者干脆

protected void RadListBox2_Inserted(object sender, RadListBoxEventArgs e)
{
    for (int i = 0; i < e.Items.Count; i++)
    {
        lblInsertedList2.Text += e.Items[i].Text + ", " + "&nbsp;";
    } 

}

希望它有帮助...

于 2015-09-28T06:26:06.177 回答