- Home
- Forum
- ASP.NET Web Forms
- Grid - inline form editing
Grid - inline form editing
Thanks for contacting Syncfusion support.
Query:1 Autocomplete not binding in inline form editing template
We have created a sample based on your requirement using inline form editing. Refer to the sample and code example as follows,
Sample: Sample-EditTemplate
|
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" > <Columns> <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="Right" Width="90" /> <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="90"> <EditTemplate Create="create" Read="read" Write="write" /> </ej:Column> <ej:Column Field="EmployeeID" HeaderText="Employee ID" EditType="Dropdown" TextAlign="Right" Width="90" /> <ej:Column Field="Freight" HeaderText="Freight" TextAlign="Right" Width="80" Format="{0:C}" EditType="Numeric" /> <ej:Column Field="ShipName" HeaderText="ShipName" Width="150" /> <ej:Column Field="ShipCountry" HeaderText="ShipCountry" Width="90" EditType="Dropdown" /> </Columns> <EditSettings AllowEditing="True" AllowAdding="True" AllowDeleting="True" EditMode="InlineForm"></EditSettings> <ToolbarSettings ShowToolbar="True" ToolbarItems="add,edit,delete,update,cancel"></ToolbarSettings> |
Refer to the Document and Demo for Edit Template in following link:
http://asp.syncfusion.com/demos/web/grid/edittemplate.aspx
http://help.syncfusion.com/aspnet/grid/editing#edit-template
We have rendered the AutoComplete control to Grid in EditTemplate write function. Refer to the code example as below.
|
[Default]
<script type="text/javascript"> function create() { return $("<input>"); }
function write(args) { obj = $('#<%= OrdersGrid.ClientID %>').ejGrid('instance');
//render autocomplete control args.element.ejAutocomplete({ width: "100%", dataSource: obj.model.columns[1].dataSource, //bind datasource showPopupButton: true, highlightSearch: true, enableDistinct: true, fields: { text: "text", key: "ID" }, watermarkText: "Select a country", filterType: 'contains', value: args.rowdata !== undefined ? args.rowdata["CustomerID"] : "" }); }
function read(args) {
. . .
} private void BindDataSource() { . . .
this.OrdersGrid.DataSource = order; this.OrdersGrid.Columns[1].DataSource = BindCountry(); this.OrdersGrid.DataBind(); }
private object BindCountry() { List<Countries> c = new List<Countries>(); c.Add(new Countries { text = "Austria", ID = "100001" }); c.Add(new Countries { text = "Australia", ID = "20002" }); c.Add(new Countries { text = "Antarctica", ID = "300003" }); c.Add(new Countries { text = "Bangladesh", ID = "400004" }); c.Add(new Countries { text = "Brazil", ID = "500005" });
return c; |
Query:2 It's possible get selected ID (not text) from Autocomplete client side ajax json
You can get the selected items ID using the getSelectedItems method in Grid Edit Template read function. Refer to the help document.http://help.syncfusion.com/js/api/ejautocomplete#methods:getselecteditems
|
function read(args) { args.ejAutocomplete('suggestionList').css('display', 'none'); var obj = args.ejAutocomplete('instance'); alert(obj.getSelectedItems()[0].ID); //get ID for the selected items return args.ejAutocomplete("getValue"); |
If we misunderstood your requirement, please share the following details.
http://help.syncfusion.com/aspnet/grid/editing#edit-mode
Regards,
Balaji Marimuthu
Based on your requirement we have created a sample. Refer to the sample and code example below.
Sample: ASPGrid(Autocomplete)
|
<div> <ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" > <Columns> <ej:Column Field="OrderID" HeaderText="Order ID" IsPrimaryKey="true" TextAlign="Right" Width="90" /> <ej:Column Field="CustomerID" HeaderText="Customer ID" Width="90"> <EditTemplate Create="create" Read="read" Write="write" /> </ej:Column> . . . .
|
We have rendered AutoComplete control in EditTemplate write function and passed the selected CustomerID data to controller using ajax. Refer to the code example and helpdocument as below.
http://help.syncfusion.com/js/api/ejautocomplete#events:select
|
function write(args) { obj = $('#<%= OrdersGrid.ClientID %>').ejGrid('instance'); var proxy = obj._id; //grid id
//render autocomplete control args.element.ejAutocomplete({ width: "100%", dataSource: obj.model.columns[1].dataSource, //bind datasource showPopupButton: true, highlightSearch: true, enableDistinct: true, fields: { text: "text", key: "ID" }, watermarkText: "Select a country", filterType: 'contains', select: function (args) { //select event in autocomplete $.ajax({ url: "/Default.aspx/dropdowndata", type: "POST", contentType: "application/json; charset=utf-8", data: JSON.stringify({ id: args.value }), dataType: "json", success: function (data) { //set value to the EmployeeID column $('#' + proxy + 'EmployeeID').val(data.d); //binding value to text box } }); }, value: args.rowdata !== undefined ? args.rowdata["CustomerID"] : "" }); [WebMethod] public static string dropdowndata(string id) { int val; if (id == "Austria") val = 3; else if (id == "Australia") val = 4; else if (id == "Antarctica") val = 5; else if (id == "Bangladesh") val = 6; else val = 8; return val.ToString(); |
In above code example, we have filled the textboxes control value in ajax success. When you want to make a column as read-only then set allowEditing as false for that column. Refer to the help document.
http://help.syncfusion.com/js/grid/columns#read-only
|
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" > <Columns> . . . <ej:Column Field="EmployeeID" HeaderText="Employee ID" AllowEditing="False" TextAlign="Right" Width="90" />
</ej:Grid> |
Regards,
Balaji Marimuthu
We are happy that the provided solution helped you.
Please get back to us if you need any further assistance. We will be happy to assist you.
Regards,
Balaji Marimuthu
- 6 Replies
- 2 Participants
-
PR Pratheep
- Oct 20, 2015 07:52 PM UTC
- Oct 23, 2015 05:02 AM UTC