I am using two radgrid controls as lists. (multiselect)then to ArrayList with custom object. I have two buttons to transfer data from 1 list to another. On the button click event I use Grid.SelectedItems to get the item from the grid. I am facing an issue where i do not always get selected item though one is selected and sometimes i get wrong selected item. Please help urgently if possible.
Below is my sample code -
aspx -
<
telerik:RadScriptManager runat="server"/>
<telerik:RadAjaxManager ID="RadAjaxManager2" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="Button3">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid3" />
<telerik:AjaxUpdatedControl ControlID="RadGrid4" />
</UpdatedControls>
</telerik:AjaxSetting>
<telerik:AjaxSetting AjaxControlID="Button4">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="RadGrid3" />
<telerik:AjaxUpdatedControl ControlID="RadGrid4" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<td cssclass="resultsRowB">
<div class="txtBold"> <asp:Literal>Available accounts</asp:Literal></div>
</td>
<td cssclass="resultsRowB">
<div class="txtBold"> <asp:Literal>Selected accounts</asp:Literal></div>
</td>
</tr>
<tr>
<td>
<telerik:RadGrid ID="RadGrid3" runat="server" OnNeedDataSource="RadGrid3_NeedDataSource" ShowHeader="false" AllowMultiRowSelection="true">
<ClientSettings>
<Selecting AllowRowSelect="True"></Selecting>
<Scrolling AllowScroll="True" UseStaticHeaders="True" ScrollHeight="100" SaveScrollPosition="True" FrozenColumnsCount="1"> </Scrolling>
</ClientSettings>
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C" />
<AlternatingItemStyle CssClass="resultsRowE" />
<ItemStyle CssClass="resultsRowE" />
<mastertableview DataKeyNames="meeting_account_id" gridlines="None" BorderWidth="1" BorderStyle=Inset CssClass="resultsRowE" showfooter="False" RetrieveAllDataFields="false" AutoGenerateColumns="False">
<Columns>
<telerik:GridBoundColumn DataField="meeting_account_id" HeaderText="ID" ReadOnly="True" SortExpression="meeting_account_id"
UniqueName="meeting_account_id" Visible="true">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="inst_inv_nm" HeaderText="Account Name" ReadOnly="True" SortExpression="inst_inv_nm"
UniqueName="inst_inv_nm" Visible="true">
</telerik:GridBoundColumn>
</Columns>
</mastertableview>
</telerik:RadGrid>
</td>
<td>
<asp:Button ID="Button3" runat="server" Text=">" OnClick="Button3_Click"></asp:Button>
<br />
<asp:Button ID="Button4" runat="server" Text="<" OnClick="Button4_Click"></asp:Button>
</td>
<td>
<telerik:RadGrid ID="RadGrid4" OnNeedDataSource="RadGrid4_NeedDataSource" ShowHeader="false" runat="server" AllowMultiRowSelection="true">
<ClientSettings>
<Selecting AllowRowSelect="True"></Selecting>
<Scrolling AllowScroll="True" UseStaticHeaders="True" ScrollHeight="100" SaveScrollPosition="True" FrozenColumnsCount="1"> </Scrolling>
</ClientSettings>
<SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C" />
<AlternatingItemStyle CssClass="resultsRowE" />
<ItemStyle CssClass="resultsRowE" />
<mastertableview DataKeyNames="meeting_account_id" gridlines="Both" showfooter="False" RetrieveAllDataFields="false" AutoGenerateColumns="False">
<Columns>
<telerik:GridBoundColumn DataField="meeting_account_id" HeaderText="ID" ReadOnly="True" SortExpression="meeting_account_id"
UniqueName="meeting_account_id" Visible="false">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="inst_inv_nm" HeaderText="Account Name" ReadOnly="True" SortExpression="inst_inv_nm"
UniqueName="inst_inv_nm" Visible="true">
</telerik:GridBoundColumn>
</Columns>
</mastertableview>
</telerik:RadGrid></td>
</tr>
aspx.cs -
protected void RadGrid3_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid3.DataSource = AvaList;
//RadGrid3.DataSource = Session["Available"];
}
protected void RadGrid4_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
RadGrid4.DataSource = SelList;
//RadGrid4.DataSource = Session["Selected"]; ;
}
protected void Button3_Click(object sender, System.EventArgs e)
{
foreach (GridDataItem item in RadGrid3.SelectedItems)
{
for (int i = AvaList.Count-1 ; i >= 0 ; i--)
{
MeetingAccount ma = AvaList[i] as MeetingAccount;
if (ma.meeting_account_id.ToString() == item["meeting_account_id"].Text)
{
AvaList.RemoveAt(i); ;
SelList.Add(ma);
break;
}
}
}
RadGrid3.Rebind();
RadGrid4.Rebind();
}
private ArrayList AvaList
{
get
{
ArrayList obj = (ArrayList)Session["AvaList"];
if (obj == null)
{
ArrayList list = new ArrayList();
MeetingAccountCollection macoll= MeetingAccountManager.GetMeetingAccountsByEvent(m_iEventId);
foreach (MeetingAccount ma in macoll)
{
list.Add(ma);
}
Session[
"AvaList"] = list;
return list;
}
return obj;
}
}
private ArrayList SelList
{
get
{
ArrayList obj = (ArrayList)Session["SelList"];
if (obj == null)
{
ArrayList list = new ArrayList();
//MeetingAccountCollection macoll = MeetingAccountManager.GetMeetingAccountsByEvent(m_iEventId);
//foreach (MeetingAccount ma in macoll)
//{
// list.Add(ma);
//}
Session[
"SelList"] = list;
return list;
}
return obj;
}
}