// Widgets cannot be created from an inherited web part if ((webpart != null) && (webpart.WebPartParentID == 0) && (category != null)) { // Create new widget object WidgetInfo newWidget = newWidgetInfo(); // Set the properties from the parent web part newWidget.WidgetName = "MyNewWidget"; newWidget.WidgetDisplayName = "My new widget"; newWidget.WidgetDescription = webpart.WebPartDescription;
newWidget.WidgetWebPartID = webpart.WebPartID; newWidget.WidgetCategoryID = category.WidgetCategoryID; // Save new widget WidgetInfoProvider.SetWidgetInfo(newWidget); returntrue; } returnfalse; }
The following example gets and updates a widget.
privatebool GetAndUpdateWidget() { // Get the widget WidgetInfo updateWidget = WidgetInfoProvider.GetWidgetInfo("MyNewWidget"); if (updateWidget != null) { // Update the properties updateWidget.WidgetDisplayName = updateWidget.WidgetDisplayName.ToLower(); // Save the changes WidgetInfoProvider.SetWidgetInfo(updateWidget); returntrue; } returnfalse; }
The following example gets and bulk updates widgets.
privatebool GetAndBulkUpdateWidgets() { // Prepare the parameters string where = "WidgetName LIKE N'MyNewWidget%'"; string orderBy = ""; int topN = 0; string columns = "";
// Get the data DataSet widgets = WidgetInfoProvider.GetWidgets(where, orderBy, topN, columns);
if (!DataHelper.DataSourceIsEmpty(widgets)) { // Loop through the individual items foreach (DataRow widgetDr in widgets.Tables[0].Rows) { // Create object from DataRow WidgetInfo modifyWidget = newWidgetInfo(widgetDr);
// Update the properties modifyWidget.WidgetDisplayName = modifyWidget.WidgetDisplayName.ToUpper();
// Save the changes WidgetInfoProvider.SetWidgetInfo(modifyWidget); } returntrue; } returnfalse; }
The following example deletes a widget.
privatebool DeleteWidget() { // Get the widget WidgetInfo deleteWidget = WidgetInfoProvider.GetWidgetInfo("MyNewWidget"); // Delete the widget WidgetInfoProvider.DeleteWidgetInfo(deleteWidget); return (deleteWidget != null); }