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
Hi,
Thank you for posting in the Infragistics community !
Your code seems fine at first glance, but the order in which you define and columns and behaviors, create editors and data bind may be essential for the proper grid functioning. Please provide the whole code so that I can see that sequence. This will enable me to investigate the issue and suggest accordingly. Looking forward to hearing from you.
Unfortunately, there is a Intellectual Property issue preventing me from posting the entire code, well, at least at the public forum level and also, there is SQL data driving the grid now.
Is there a blog or sample that could show case the order? Do you need a functioning solution or you just need to look at the code?
Hi Pavel,
Thank you from quick response.
Just the workflow should be enough, for example smth like:
Page_Load
// binding grid with sample code how you do it
Page_Pre_Init
// adding columns with sample code how you do it
// call method to configure behaviors
grid events
<grid markup>
I will be able to create a sample following this scenario. If it reproduces the issue I will investigate it, if not I can send it to you to further modify it in order to reproduce the issue. It is also possible that I move this case out of the forum if you want to share something that is not suitable for the forum.
Please let me know how you wish to proceed with this.
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?
As a side note, the grid is located inside a webtab. I have other issues with the ability for the web grid to occupy 100% height of the actual web tag content and for the actual web tab to occupy 100% of the page, but that is a different CSS/style issue that I haven't been able to address, but will address it later.
Back on point, the webgrid ends up being data-bound once I click on an image button and on post-back, I add the columns dynamically within the click method and then bind the data. What options do I have for posting the files? Could I send them across to you? I can post the solution to this thread to close it off once we figure out the problem.
Next steps?
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); }
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.