<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> |
[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; |
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"); |
http://help.syncfusion.com/aspnet/grid/editing#edit-mode
Regards,
Balaji Marimuthu
<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> . . . .
|
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(); |
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" > <Columns> . . . <ej:Column Field="EmployeeID" HeaderText="Employee ID" AllowEditing="False" TextAlign="Right" Width="90" />
</ej:Grid> |