Hi everyone,
Any and all assistance here is greatly appreciated!
I'm trying to implement a Listbox Transfer scenario - allowing typical moving items from one list box to another.
The transferring of items back and forth is working fine.
The part that isn't working is getting changes to update a SQL database.
But once something is moved, the underlying dataTable doesn't have any changes.
What am I missing in order to acknowledge changes in the Selected dataTable?
Thank you in advance.
Here's the listboxes defined:
<telerik:RadListBox ID="RadListBox1" CssClass="RadListBoxAvailable" runat="server" SelectionMode="Multiple" AllowTransfer="True" TransferToID="RadListBox2" AllowTransferOnDoubleClick="True" EnableDragAndDrop="True" OnTransferred="RadListBox1_Transferred" AutoPostBackOnTransfer="True" Sort="Ascending"></telerik:RadListBox> <telerik:RadListBox ID="RadListBox2" CssClass="RadListBoxSelected" runat="server" SelectionMode="Multiple" AllowTransferOnDoubleClick="True" EnableDragAndDrop="True" AutoPostBackOnTransfer="True" Sort="Ascending"></telerik:RadListBox>And here's the c#:
using System;using System.Configuration;using System.Data;using System.Data.SqlClient;using Telerik.Web.UI;public partial class testX : System.Web.UI.Page{ public static DataTable dtSelected; protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadAvailable(); LoadSelected(); } } private void LoadAvailable() { string query = "select personId, person from peopleList"; RadListBox1.DataSource = GetDataTable(query); RadListBox1.DataSortField = "person"; RadListBox1.DataTextField = "person"; RadListBox1.DataValueField = "personId"; RadListBox1.DataBind(); } private void LoadSelected() { string query = "select personId, person from peopleChosen"; dtSelected = GetDataTable(query); RadListBox2.DataSource = dtSelected; RadListBox2.DataTextField = "person"; RadListBox2.DataSortField = "person"; RadListBox2.DataValueField = "personId"; RadListBox2.DataBind(); } private DataTable GetDataTable(string query) { String ConnString = ConfigurationManager.ConnectionStrings["wareConnectionString"].ConnectionString; SqlConnection conn = new SqlConnection(ConnString); SqlDataAdapter adapter = new SqlDataAdapter(); adapter.SelectCommand = new SqlCommand(query, conn); DataTable myDataTable = new DataTable(); conn.Open(); try {adapter.Fill(myDataTable);} finally {conn.Close();} return myDataTable; } protected void RadListBox1_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e) { if (DataTableHasChanges(dtSelected)) { LabelEditStatus.Text = "Changes not Saved"; } else { LabelEditStatus.Text = ""; } } public bool DataTableHasChanges(DataTable dataTable) { return (dataTable != null) ? dataTable.GetChanges() != null : false; } }