Hi,
I have two grids. The first grid has a checkbox column and when the checkbox is checked, the corresponding row should be added to the second grid.
I have tried http://www.telerik.com/community/forums/thread/b311D-ekbdh.aspx
But in the example, button triggers the method where selected items get moved but in my case, I need to use the embedded checkbox column to move a selected row but the second grid doesn't get populated after the method where a selected row gets moved. but a strange thing is that when I click a column heading as if sorting then all of sudden the records show up in the second radgrid.
here is my code,
My first grid
The second Grid
NeedDataSource Methods
commentTemplates and selectedCommentTemplates properties
Lastly checkbox serverside event
Thank you in advance,
Toby
I have two grids. The first grid has a checkbox column and when the checkbox is checked, the corresponding row should be added to the second grid.
I have tried http://www.telerik.com/community/forums/thread/b311D-ekbdh.aspx
But in the example, button triggers the method where selected items get moved but in my case, I need to use the embedded checkbox column to move a selected row but the second grid doesn't get populated after the method where a selected row gets moved. but a strange thing is that when I click a column heading as if sorting then all of sudden the records show up in the second radgrid.
here is my code,
My first grid
<radG:RadGrid |
ID="RadGrid_QueryComments" |
EnableAJAX="true" |
runat="server" |
OnNeedDataSource="RadGrid_QueryComments_NeedDataSource" |
Title="Double Click on the comment template to Select it."> |
<PagerStyle Mode="NumericPages"></PagerStyle> |
<MasterTableView Width="100%" DataKeyNames="commentNo" GroupLoadMode="Client"> |
<Columns> |
<radG:GridTemplateColumn HeaderText="Select"> |
<ItemTemplate> |
<asp:CheckBox runat="server" Text='<%# Eval("commentNo") %>' AutoPostBack="true" OnCheckedChanged="ckbSelectedCommentTemplate_CheckedChanged" ID="ckbSelectedCommentTemplate" /> |
</ItemTemplate> |
</radG:GridTemplateColumn> |
The second Grid
<radG:RadGrid ID="RadGrid_SelectedCommentNos" |
EnableAJAX="true" |
AllowSorting="true" |
AllowPaging="true" |
AllowMultiRowSelection="true" |
runat="server" |
OnNeedDataSource="RadGrid_SelectedCommentNos_NeedDataSource"> |
<ClientSettings ApplyStylesOnClient="true"> |
<Selecting AllowRowSelect="true" /> |
</ClientSettings> |
</radG:RadGrid> |
NeedDataSource Methods
protected void RadGrid_QueryComments_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e) |
{ |
((RadGrid)source).DataSource = this.commentTemplates; |
} |
protected void RadGrid_SelectedCommentNos_NeedDataSource(object source, Telerik.WebControls.GridNeedDataSourceEventArgs e) |
{ |
RadGrid_SelectedCommentNos.DataSource = this.selectedCommentTemplates; |
} |
commentTemplates and selectedCommentTemplates properties
public DataTable commentTemplates |
{ |
get |
{ |
object res = this.ViewState["commentTemplates"]; |
if (res != null) |
{ |
return (DataTable)res; |
} |
// I am just showing pseudocode here |
// get default records |
// save into ViewState["commentTemplates"] |
// finally |
return theResult; |
} |
} |
public DataTable selectedCommentTemplates |
{ |
get |
{ |
object res = this.ViewState["selectedCommentTemplates"]; |
if (res != null) |
{ |
return (DataTable)res; |
} |
else |
{ |
// get default value |
// insert into ViewState["selectedCommentTemplates"] |
// return theResults |
} |
} |
set |
{ |
ViewState["selectedCommentTemplates"] = value; |
} |
} |
Lastly checkbox serverside event
protected void ckbSelectedCommentTemplate_CheckedChanged(object sender, EventArgs e) |
{ |
DataSet selectedCommentTemplateData = new DataSet(); |
DataTable existingData = selectedCommentTemplates; |
if (((CheckBox)sender).Checked) |
{ |
// fill selectedCommentTemplateData with this selected record |
existingData.Merge(selectedCommentTemplateData.Tables[0]); |
selectedCommentTemplates = existingData; |
} |
else |
{ |
existingData.Rows.Remove(commentTemplates.Select("commentNo=" + ((CheckBox)sender).Text)[0]); |
selectedCommentTemplates = existingData; |
} |
RadGrid_SelectedCommentNos.Rebind(); |
} |
Thank you in advance,
Toby