Pretty new to infragistics. i am using asp.net web forms
i have a wdg that is editable. For one of the columns, i would like to have a dropdown list.
i have tried both templates and providers, with limited success. Which is best for my application ?
the column in the grid is supervisor_emp_id
the dropdown is populated with emp_id and name
thanks
Hello Peter,
There is a similar forum post where I have provided an answer to the question. To sum it up you would need to use the ItemTemplate of the dropdown and use another WebDataGrid inside it, which is used as a multi-column dropdown, when the user selects a row the RowSelectionChanged event is used to set the value of the dropdown. There is also a small sample application that demonstrates how this could be achieved, below you can find the link for the forum post:
https://www.infragistics.com/community/forums/f/ultimate-ui-for-asp-net-web-forms/123044/databound-multi-column-dropdown-in-webdatagrid
Please let me know if you need any further assistance.
Regards, Ivan Kitanov
I have got this working from another example. I populate the dropdown server side onrowinit.
it seems to work.
Question, how do i access the sci_id in javascript SCI_ValueChanged event ?
<ig:TemplateDataField Key="tloge_sci" Width="90px" Header-Text="USI/SCI"> <ItemTemplate> <ig:WebDropDown ID="wdd_sci" runat="server" TextField="sci_id" Width="80px" DataKeyFields="sci_id" AutoSelectOnMatch="true" EnableAutoCompleteFirstMatch="False" EnableClosingDropDownOnSelect="true">
<ClientEvents ValueChanged="SCI_ValueChanged" />
<HeaderTemplate> <table id="TemplateContainer"> <tr class="igg_row"> <td class="igg_HeaderCaption" style="width: 90px;">USI/SCI</td> <td class="igg_HeaderCaption" style="width: 500px;">Description</td> </tr> </table> </HeaderTemplate> <ItemTemplate> <table style="width: 100%" cellspacing="0" cellpadding="4"> <tr class="igg_row"> <td style="width: 100px;"> <%# DataBinder.Eval(Container.DataItem, "sci_id")%> </td> <td style="width: 500px;"> <%# DataBinder.Eval(Container.DataItem, "description")%> </td> </tr> </table> </ItemTemplate> </ig:WebDropDown> </ItemTemplate> </ig:TemplateDataField>
You can get the value from the ValueChanged event with the following code:
let value = e.getNewValue(); // where “e” is the eventArgs
If you would like to use the new value with some logic concerning the row of that cell with the dropdown, then I recommend you using the EditingCore-CellValueChanged event instead. The reason for this is that it would be way easier to find the row with the CellValueChanged event, all it needs to be done is checking if the cell belongs to the column with the dropdown. A code for this should be similar to the code below:
function wdg_CellValueChanged(sender, e){ if (e.get_cell().get_column().get_key() === "tloge_sci") { let value = e.get_cell().get_value(); let row = e.get_cell().get_row(); //add any custom logic } }
Thanks for the response. I tried that but threw an error on runtime saying no such event.
i made some headway on this.
e.get_value() works
'row' (below) also returns the correct value in the grid
I also have these two events defined, which fire when editing other 'regular' columns
are edited.
EnteredEditMode="wdg_CellEditing_EnteredEditMode" ExitedEditMode="wdg_CellEditing_ExitedEditMode"
3 questions.
1. How would I retrieve the dropdown 'description' from the code below ? I want to set a grid field
to its value
2. Why doesnt the dropdown selection put the grid row into Edit mode ? (the above events do
not get fired) How would i do that in code below ?
3. How would I move the focus to another field in edit mode
Am i better off with wdg in my template field or use EditorProvider ? Hard to
know the best approach. I have been messing around with above for 2 days.
It would be nice if you folks had an official example of a grid with a multi-column
dropdown with a save button to save data. You do have a bunch of different
examples but not the multicolumn dropdown in a grid.
Essentially, what i want to do would be similar to a State , State Name dropdown
in a grid which displays both but saves only State
I appreciate your guidance on this.
function SCI_ValueChanged(sender, e) { var grid = $find("<%= wdg.ClientID %>");
// Make sure we get the row the drop is on, not the one selected var parentRow = sender.get_element().parentElement.parentElement._object.get_index();
var row = grid.get_rows().get_row(parentRow);
var sci = e.get_value();
...
I have created a sample that follows your approach that uses a TemplatedField with WebDropDown, which uses tables to display multiple columns. In order to access the data source of the WebDropDown and set the value of a field based on the selection that the user has made, I recommend you serializing the data to a JSON string and then extracting the needed data based on the index of the selected item. The serializing could be done with the help of the following method:
public string ConvertDataTabletoString() { DataTable dt = (DataTable)Session["DS"]; System.Web.Script.Serialization.JavaScriptSerializer serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>(); Dictionary<string, object> row; foreach (DataRow dr in dt.Rows) { row = new Dictionary<string, object>(); foreach (DataColumn col in dt.Columns) { row.Add(col.ColumnName, dr[col]); } rows.Add(row); } return serializer.Serialize(rows);
I was able to reproduce the behavior, where the grid doesn’t enter edit mode on the TemplatedField, I would need some more time to investigate what might be causing this. If you would like to move enter edit mode to another field the following line could be used:
grid.get_behaviors().get_editingCore().get_behaviors().get_cellEditing().enterEditMode(cell);
You can find the sample attached below. Please test it on your side and let me know if you have any questions.
TemplateFieldMultiColumnDropDown.zip