M
maciu
Hi,
I have a problem with DataTable.Select method in Microsoft .NET 2.0.
I have a ListBox control, with DataSource pointing to a DataTable
"RolePermissions". ListBox has SelectionMode property set to
"Multiple".
I would like to enable User to Delete Multiple items with just one
click.
I am almost sure, that this worked in .NET 1.1.
I have a DataTable with column "permissionID" of type uniqueidentifier
Here is my Code:
// We will concatenate selected Guid's into one string
StringBuilder sbItemsSelected = new StringBuilder();
// for every Item ....
foreach (ListItem item in lbRolePermissions.Items)
{
// ... which is selected...
if (item.Selected == true)
{
// ...we add selected ID, and space after it
sbItemsSelected.Append("'");
sbItemsSelected.Append(item.Value);
sbItemsSelected.Append("' ");
}
}
/// We now have list of ID's, separated with spaces (with space at he
end)
string selectedItems = sbItemsSelected.ToString();
// remove last space
selectedItems = selectedItems.Trim();
// insert commas instead of spaces
selectedItems = selectedItems.Replace(" ", ",");
// get the table, to handle data
DataTable dtRolePermissions = Session["RolePermissions"] as DataTable;
/// select rows, which are of interest to us
********************************************************************
DataRow[] drsRolePermissions =
dtRolePermissions.Select("permissionID IN (" + selectedItems + ")");
*********************************************************************
/// delete them
foreach (DataRow drRolePer in drsRolePermissions)
{
drRolePer.Delete();
}
/// save new Table in Session variable
Session["RolePermissions"] = dtRolePermissions;
// bind the Table again
lbRolePermissions.DataSource = dtRolePermissions;
lbRolePermissions.DataBind();
The line inside "stars" is line, in which an exception occurs, the
exception Message is:
"Cannot perform '=' operation on System.Guid and System.String."
I thought, that exception can occur because the Items in listBox are
filtered with an expression, but that would be stupid of Microsoft not
to let such operations.
I am confused.... this really worked in .NET 1.1
I used it a lot in previous applications....
Is there some explanation to this fact ?
( apart from saying, that this is a bug ;-) )
Thank You in advance for help,
maciu
I have a problem with DataTable.Select method in Microsoft .NET 2.0.
I have a ListBox control, with DataSource pointing to a DataTable
"RolePermissions". ListBox has SelectionMode property set to
"Multiple".
I would like to enable User to Delete Multiple items with just one
click.
I am almost sure, that this worked in .NET 1.1.
I have a DataTable with column "permissionID" of type uniqueidentifier
Here is my Code:
// We will concatenate selected Guid's into one string
StringBuilder sbItemsSelected = new StringBuilder();
// for every Item ....
foreach (ListItem item in lbRolePermissions.Items)
{
// ... which is selected...
if (item.Selected == true)
{
// ...we add selected ID, and space after it
sbItemsSelected.Append("'");
sbItemsSelected.Append(item.Value);
sbItemsSelected.Append("' ");
}
}
/// We now have list of ID's, separated with spaces (with space at he
end)
string selectedItems = sbItemsSelected.ToString();
// remove last space
selectedItems = selectedItems.Trim();
// insert commas instead of spaces
selectedItems = selectedItems.Replace(" ", ",");
// get the table, to handle data
DataTable dtRolePermissions = Session["RolePermissions"] as DataTable;
/// select rows, which are of interest to us
********************************************************************
DataRow[] drsRolePermissions =
dtRolePermissions.Select("permissionID IN (" + selectedItems + ")");
*********************************************************************
/// delete them
foreach (DataRow drRolePer in drsRolePermissions)
{
drRolePer.Delete();
}
/// save new Table in Session variable
Session["RolePermissions"] = dtRolePermissions;
// bind the Table again
lbRolePermissions.DataSource = dtRolePermissions;
lbRolePermissions.DataBind();
The line inside "stars" is line, in which an exception occurs, the
exception Message is:
"Cannot perform '=' operation on System.Guid and System.String."
I thought, that exception can occur because the Items in listBox are
filtered with an expression, but that would be stupid of Microsoft not
to let such operations.
I am confused.... this really worked in .NET 1.1
I used it a lot in previous applications....
Is there some explanation to this fact ?
( apart from saying, that this is a bug ;-) )
Thank You in advance for help,
maciu