I have seen a number of posts about the ability to have a DropdownProvider in my web data grid, but can't seem to get it to show. This is how I have my web data grid defined are:
<ig:WebDataGrid ID="dgCompatibilityViewData" runat="server" Width="100%" StyleSetName="LucidDream" OnPreRender="dgCompatibilityViewData_PreRender"> <EditorProviders> <ig:DropDownProvider ID="ddlCompatibilityValues"> <EditorControl runat="server" ID="CompatibilityDropDown" ClientIDMode="Predictable" DropDownContainerMaxHeight="200px" EnableAnimations="False" EnableDropDownAsChild="False" DisplayMode="DropDownList" TextField="Compatibility"> <Items> <ig:DropDownItem Selected="False" Text="V" Value="V"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="C" Value="C"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="L" Value="L"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="X" Value="X"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="W" Value="W"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="-" Value="-"> </ig:DropDownItem> </Items> <DropDownItemBinding ValueField="Compatibility" TextField="Compatibility" /> </EditorControl> </ig:DropDownProvider> </EditorProviders> <EmptyRowsTemplate> <div style="text-align: center"> <br /> <br /> <asp:Label runat="server" ID="emptyWgLAbel" Text="Select two sets of products to view compatibility info using the drop down menu's above."></asp:Label> </div> </EmptyRowsTemplate> </ig:WebDataGrid>
and based on a specified event, data is to be loaded dynamically, column data is also dynamic, so I generate the DataBoundColumns programmatically, and define the one column that should appear with drop-down options using this code:
//Compatibility Column BoundDataField compatibilityField = new BoundDataField(true); compatibilityField.Key = "Compatibility"; compatibilityField.Header.Text = productName; EditingCore core = new EditingCore(); core.Enabled = true; core.AutoCRUD = false; CellEditing editing = new CellEditing(); core.Behaviors.Add(editing);
EditingColumnSetting setting = new EditingColumnSetting(); setting.ColumnKey = "Compatibility"; setting.EditorID = dgCompatibilityViewData.EditorProviders[0].ID; editing.ColumnSettings.Add(setting);
dgCompatibilityViewData.Columns.Add(compatibilityField);dgCompatibilityViewData.Behaviors.Add(core);
I must be missing something???
Paul
Hello Pavel,
When defining behaviors in code behind this needs to be done in the Init event, so that they are build every time the page reinitializes itself. This was the issue with your sample - after binding grid to the new data behaviors were not created. Here is the Init event with the sample code you need to move in there:
protected void WebDataGrid1_Init(object sender, EventArgs e) { EditingCore core = new EditingCore(); core.Enabled = true; core.AutoCRUD = false; CellEditing editing = new CellEditing(); core.Behaviors.Add(editing);
EditingColumnSetting setting = new EditingColumnSetting(); setting.ColumnKey = "field2"; setting.EditorID = WebDataGrid1.EditorProviders[0].ID; editing.ColumnSettings.Add(setting);
WebDataGrid1.Behaviors.Add(core); }
Please let me know if you would need the modified sample so that I can attach it here too.
ok, I have a sample. Seems like the problem occurs after a table merge. The original table (when loaded) contains the proper drop-down behavior on a double-click, but when I add more data to the grid via the button, and merge. I am now unable to enter edit state on the table.
The only minor difference is that when I create the edit behavior, there is no actual data, but just column definitions. And then another user action adds data to the table and I call the table.merge method, so I can combine data, and refresh the grid. I would have assumed table behavior would remain intact???
Sample attached.
So, this is my grid definition:
<ig:WebDataGrid ID="myGrid" runat="server" Width="100%" StyleSetName="LucidDream" OnPreRender="myGrid_PreRender"> <EditorProviders> <ig:DropDownProvider ID="ddlCompatibilityValues"> <EditorControl runat="server" ID="CompatibilityDropDown" ClientIDMode="Predictable" DropDownContainerMaxHeight="200px" EnableAnimations="False" EnableDropDownAsChild="False" DisplayMode="DropDownList" TextField="Compatibility"> <Items> <ig:DropDownItem Selected="False" Text="V" Value="V"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="C" Value="C"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="L" Value="L"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="X" Value="X"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="W" Value="W"> </ig:DropDownItem> <ig:DropDownItem Selected="False" Text="-" Value="-"> </ig:DropDownItem> </Items> <DropDownItemBinding ValueField="Compatibility" TextField="Compatibility" /> </EditorControl> </ig:DropDownProvider> </EditorProviders> </ig:WebDataGrid>
and the various methods that you are requesting. These sequence of events display the table headers. There is a method we call that merges data into an existing datatable and then we databind. Actual data shows up on a secondary databind after merging in existing data. I have no problem uploading solution, just can't do it to this post in its entirety.
protected void Page_Load(object sender, EventArgs e) { //initialize fields and the UI when it is initially rendered and not during a postback. if (!IsPostBack) {
//initialize some data and session variables based on loading a page.
}
//rebind data after AJAX postback if (Session["gridData"] != null) { dgCompatibilityViewData.DataSource = (DataTable)Session["MatrixData"]; dgCompatibilityViewData.DataBind(); } }
and after selecting a specific event after a drop_down selection change, I perform the following:
protected void cbx_SelectionChanged(object sender, DropDownSelectionChangedEventArgs e) { DataTable table = Controllers.DataAccess.getInstance().getEditMode(cbx.SelectedValue);
//we are re-generating column types, so clear up the datasource and columns, and rebind. myGrid.ClearDataSource();myGrid.Columns.Clear();myGrid.AutoGenerateColumns = false; GenerateEditModeColumns(cbx.SelectedValue);
myGrid.DataSource = table;
myGrid.DataBind();
if (Session["MatrixData"] == null) Session.Add("MatrixData", table); else Session["MatrixData"] = table;
Session["EditMode"] = true;
private void GenerateEditModeColumns(string somedata) { string productName = Controllers.DataAccess.getInstance().getProductName(somedata);
//ID Column
BoundDataField idField = new BoundDataField(true); idField.Key = "id"; idField.Header.Text = "ID"; idField.Hidden = true; idField.DataFieldName = "id";
//Product Column BoundDataField productField = new BoundDataField(true); productField.Key = "Product"; productField.Header.Text = "Product"; productField.DataFieldName = "Product";
//Is Published Column BoundCheckBoxField isPublishedField = new BoundCheckBoxField(true); isPublishedField.Key = "IsPublished"; isPublishedField.Header.Text = "Is Published";
//Notes Column BoundDataField notesField = new BoundDataField(true); notesField.Key = "Notes"; notesField.Header.Text = "Notes";
//Set up the columns in the data grid. dgCompatibilityViewData.Columns.Add(idField); dgCompatibilityViewData.Columns.Add(productField); dgCompatibilityViewData.Columns.Add(compatibilityField); dgCompatibilityViewData.Columns.Add(isPublishedField); dgCompatibilityViewData.Columns.Add(notesField);
dgCompatibilityViewData.Behaviors.Add(core); }
Hi Pavel,
1) will all values in the column default to a drop-down, if everything is to work as intended? Or, do I need to click/double-click on a value to place it in edit mode?
What would mean a value to default to a drop-down ? The value in the cell will be as it comes from the data source. The dropdown editor however may impose textKey and valueKey options, so the cell may contain a value of 0, but display the string "text 0" in the field. This will happen if the dropdown editor maps the value 0 to the string "text 0". The default method to enter edit mode is to double click over the cell, but this is a configurable behavior via the EditModeActions property.
2) As mentioned beforehand please provide an example on how you define and add columns to the grid and the event where you data bind. Also the logic in Page_Load - does it include defining columns and binding ? This will be enough for me to create a sample following this scenario and try to reproduce and investigate.
Next steps?