2015-09-22 31 views
0

1.)我使用下面的代碼將項目從一個RadListBox轉移到另一個。獲取所有轉移的RadListBox項目標籤並使用RadListBox_items綁定RadGrid,ID

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"; 
} 

我想從RadListBox1轉移項目到RadListBox2一個Label控件內部(比如lblInsertedList2標籤),因爲後面我必須根據RadListBox2內的項目綁定RadGrid
爲此,我創建了RadListBox2_Inserted事件,其中我試圖在Label中獲取RadListBox2的項目。
現在,當我將多於1項RadListBox1傳輸到RadListBox2(使用Ctrl按鈕)時,將重複第1個選定項目。

示例: RadListBox1具有「a」,「b」,「c」項。 當我從RadListBox1傳輸所有 「一」, 「B」, 「C」 一起向RadListBox2(使用CTRL鍵)

我看到下面的輸出:aababc

正確的輸出應爲:ABC

請查看以下快照上述問題: enter image description here 再次,RadListBox1有 「A」, 「b」, 「C」 項目 當我從RadListBox1傳輸項目1 1至RadListBox2

Eample: 當我只轉移一個,我看下面的輸出:a(第一次) 當我只轉b時,我看下面輸出:a,a(第二次) 當我只轉c時,我看到下面輸出:a ,A,A(第三次)

請檢查下面的快照上面的問題: enter image description here
2)我想RadGrid使用綁定:

  • _SPID =請求。查詢字符串[「SPID」]
  • 項目獲得的RadListBox2(僅從RadListBox1所選項目)

現在我只用Request.QueryString["SPID"]結合RadGrid,所以我得到的所有與「SPID」

數據

實施例:

  SPID    RadListBox1_Items   值

 一個                  TEST1

    b                   TEST2

   Ç                  TEST3

我的要求是:如果想在RadListBox2只拿到了2項 「A」, 「C」 然後RadGrid數據應基於RadListBox2項目和「SPID」綁定

SPID       RadListBox2_Items      值

 一個                  TEST1

   Ç                  TEST3

我希望我做了我的要求明確。請讓我知道是否有任何困惑。請回答這兩點。
在此先感謝。

+0

我認爲對於 - 環在插入的情況下,使問題... – Sankar

+0

@SankarRaj:謝謝你的回覆。我在'e.Items.Count'中得到了正確的記錄,所以我應該改變什麼呢? – user3196511

回答

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;"; 
    } 

} 

希望它能幫助...

相關問題