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

[Solved] Selected row not always correct

1 Answer 123 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Chaitali
Top achievements
Rank 1
Chaitali asked on 28 Apr 2009, 08:04 PM
Hi,
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;

 

}

}

1 Answer, 1 is accepted

Sort by
0
Sebastian
Telerik team
answered on 04 May 2009, 01:26 PM

Hello Chaitali,

I think that the sample project from the code library thread linked below can become a starting point for your implementation:

http://www.telerik.com/community/code-library/aspnet-ajax/grid/dual-listbox-functionality.aspx

Review the information/code snippets in it for more details. Feel free to modify/extend the solution to match your custom requirements.

Best regards,

Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Chaitali
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Share this question
or