In WebDataGrid column, I had used UnBoundField for displaying Dropdown. On Add button(which is placed outside grid) click, I want to display dropdown in unbounded field, otherwise this unbounded field will display already saved text(ie no dropdown in grid.)
Below is the code I am using to display dropdown
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="400px" Width="100%" AutoGenerateColumns="false" DataKeyFields="ID" > <Columns> <ig:UnboundField Key="Name" Width="350px" Header Text="Name" /> </ig:UnboundField> ....... <Columns> <EditorProviders> <ig:DropDownProvider ID="NameProvider"> <EditorControl ID="editName" runat="server" DisplayMode="DropDownList" TextField="SName" ValueField="SName" /> </ig:DropDownProvider></EditorProviders> <Behaviors> <ig:EditingCore> <Behaviors> <ig:CellEditing Enabled="true"> <ColumnSettings> <ig:EditingColumnSetting ColumnKey="Name" EditorID="NameProvider" /> </ColumnSettings> </ig:CellEditing> </Behaviors> </ig:EditingCore> </Behaviors> </ig:WebDataGrid><asp:Button Id="btnAdd" runat="server" Text="Add Name" onclick="btnAdd_Click"/>What's the best way to show dropdown in some rows on unboundedField?
Hi,
Thank you for the markup shared. The best way to display any editor (including DropDown) in any WebDataGrid column is defining the editor as you have did and use the corresponding behavior column settings to set it as editor for a given column:
<ig:EditingColumnSetting ColumnKey="Name" EditorID="NameProvider" />
It does not matter that the given column is UnboundField. Please let me know if you have further questions on the matter.
Thanks Hristo for replying.
I had already added the specified line. My problem is that I don't want to display dropdown on all rows. Currently on all rows dropdown is displayed. But I want to display dropdown only on new rows which are created on Add button click.
When you hit the Add button, does this adds a real row to the grid , or it just displays a row where the user can enter values for a new row ? Please clarify to clear things out to me.
Sorry for the delay in replying.
It creates a real row on Adding.
Not only on adding but sometimes I have to display dropdown on few rows(not all rows) depending on some condition?
Hi Birenda,
TemplateDataFields are not bound to a data source field and therefore do not relate to the grid editing behavior. If you have a WebDropDown in a TenmplateDataField and want to show it only on certain rows, you can implement custom logic that will disable the dropdowns on those rows. Please let me know if this would work for you.
Please do send a sample because I had used eventArgs.set_cancel(true); but it didnot work on template field containing dropdown.
Hi Birendra,
Thanks for the information. When displaying a dropdown depends on the behavior - cell/row editing and RowAdding, it is just a matter of the behavior ColumnSettings as I believe you are already aware. So for displaying a dropdown on row adding you should configure that in the RowAdding column settings.
When displaying dropdowns in the grid rows for row editing/cell editing, the only way you could achieve showing dropdowns on given rows only, is the following:
Configure dropdown editors as you would in the behavor ColumnSettings. Handle the enteringEditMode client side event of the behavior and cancel it, if you don't want to display a dropdown for the given row/column:
function WebDataGrid1_CellEditing_EnteringEditMode(sender, eventArgs){ if (eventArgs.getCell().get_row().get_index() % 2 === 0) { eventArgs.set_cancel(true); }}
Please let me know if you need me to send a sample demonstrating this approach.
As you see cancelling here means you will not be able to perform editing on the given cell/row and I am not sure if this is ok with your scenario. You could let me know that and I will think for al alternative, however the probability to achieve that is no high.