private void 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 = "Bangladesh", ID = "300003" });
this.ShipCountry.DataSource = c;
ShipCountry.DataTextField = "text";
ShipCountry.DataUniqueKeyField = "ID";
ShipCountry.DataBind();
}
[Serializable]
class Countries {
public string text;
public string ID;
}
protected void EditEvents_ServerEditRow(object sender, GridEventArgs e)
{
EditAction(e.EventType, e.Arguments["data"]);
}
protected void EditEvents_ServerAddRow(object sender, GridEventArgs e)
{
EditAction(e.EventType, e.Arguments["data"]);
}
<ej:Grid ID="OrdersGrid" runat="server" AllowPaging="True" OnServerEditRow="EditEvents_ServerEditRow" OnServerAddRow="EditEvents_ServerAddRow" OnServerDeleteRow="EditEvents_ServerDeleteRow"> <ClientSideEvents ActionComplete="complete" EndAdd="endAdd" EndDelete="endDelete" EndEdit="endEdit" /> … </ej:Grid> </ContentTemplate> </asp:UpdatePanel> </div> <script type="text/template" id="template"> <b>Order Details</b> <table cellspacing="10"> <tr> <td style="text-align: right;">ShipCountry </td> <td style="text-align: left"> <input id="ShipCountry1" name="ShipCountry" class="e-field e-ejinputtext valid" style="width: 116px; height: 28px" value="{{:ShipCountry}}" /> </td> </tr> </table> </script> <script type="text/javascript"> function complete(args) { if ((args.requestType == "beginedit" || args.requestType == "add") && args.model.editSettings.editMode == "dialogtemplate") { … var obj = $(".e-grid").ejGrid("instance"); var data = ej.DataManager(obj.model.dataSource).executeLocal(new ej.Query().select("ShipCountry")); $("#ShipCountry1").ejAutocomplete({ width: "100%", dataSource: data, enableDistinct: true}); } } </script> |
<asp:HiddenField runat="server" ID="autoComp" ClientIDMode="Static" /> …… <script type="text/javascript"> function complete(args) { if (args.requestType == "refresh" || args.requestType == "save") { $('#<%= OrdersGrid.ClientID %>').ejWaitingPopup("hide"); } if ((args.requestType == "beginedit" || args.requestType == "add") && args.model.editSettings.editMode == "dialogtemplate") { .. data1 = [ { ID: "100001", text: "Germany" }, { ID: "20002", text: "Australia" }, { ID: "300003", text: "Bangladesh" }, ]; var obj = $(".e-grid").ejGrid("instance"); $("#ShipCountry1").ejAutocomplete({ width: "100%", dataSource: data1, select: function (argument) { $("#autoComp").val(JSON.stringify(argument.item)); }, enableDistinct: true }); } } ….. protected void EditEvents_ServerEditRow(object sender, GridEventArgs e) { var item = this.autoComp.Value; JavaScriptSerializer mySerialiser = new JavaScriptSerializer(); var selectedrow = mySerialiser.Deserialize<object>(item); // here you will get records EditAction(e.EventType, e.Arguments["data"]); } |
public IEnumerable AutoDataSource; private List<Orders> order = new List<Orders>(); … private void 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 = "Bangladesh", ID = "300003" }); this.AutoDataSource = c; .. } ………………………. function complete(args) { if ((args.requestType == "beginedit" || args.requestType == "add") && args.model.editSettings.editMode == "dialogtemplate") { .. var data1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.AutoDataSource)%>'); $("#ShipCountry1").ejAutocomplete({ width: "100%", dataSource: data1, select: function (argument) { $("#autoComp").val(JSON.stringify(argument.item)); }, enableDistinct: true }); } |
if ((args.requestType == "beginedit" || args.requestType == "add") && args.model.editSettings.editMode == "dialogtemplate") {
var data1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.AutoDataSource)%>');
$("#ShipCountry1").ejAutocomplete({
width: "100%", dataSource: data1,
select: function (argument) {
$("#autoComp").val(JSON.stringify(argument.item));
},
enableDistinct: true
});
}
code behind country text and code is empty
var item = this.autoComp.Value;
JavaScriptSerializer mySerialiser = new JavaScriptSerializer();
var data = mySerialiser.Deserialize<object>(item);
Thanks
Pratheep
[WebForm2.aspx.cs] public partial class WebForm2 : System.Web.UI.Page { public IEnumerable AutoDataSource; … private void bindcountry() { … this.AutoDataSource = c; … |
private void 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 = "Bangladesh", ID = "300003" });
this.AutoDataSource = c;
this.ShipCountry.DataSource = c;
ShipCountry.DataTextField = "text";
ShipCountry.DataUniqueKeyField = "ID";
ShipCountry.DataBind();
}
var data1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.AutoDataSource)%>');
$("#ShipCountry1").ejAutocomplete({
width: "100%", dataSource: data1,
select: function (argument) {
$("#autoComp").val(JSON.stringify(argument.item));
},
enableDistinct: true
});
protected void EditEvents_ServerEditRow(object sender, GridEventArgs e)
{
var item = this.autoComp.Value;
JavaScriptSerializer mySerialiser = new JavaScriptSerializer();
var data = mySerialiser.Deserialize<object>(item); // here I'm getting empty records
EditAction(e.EventType, e.Arguments["data"]);
}
[Default.aspx.cs] namespace Sample { public partial class Default : System.Web.UI.Page { public IEnumerable AutoDataSource; IEnumerable a = new NorthwndDataContext().Orders.ToList(); private List<Orders> order = new List<Orders>(); … private void bindcountry() { … this.AutoDataSource = a; … } } } [Default.aspx] … <form id="form1" runat="server"> … <asp:HiddenField runat="server" ID="autoComp" ClientIDMode="Static" /> … function complete(args) { … var data1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.AutoDataSource)%>'); var data = ej.DataManager(data1).executeLocal(new ej.Query().select("OrderID", "ShipCountry")); $("#ShipCountry1").ejAutocomplete({ width: "100%", dataSource: data, fields: { text: "ShipCountry", key: "OrderID" }, select: function (argument) { $("#autoComp").val(JSON.stringify(argument.item)); }, enableDistinct: true }); } |
//Code behind
public IEnumerable AutoDataSource;
// List of countries
private void 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 = "Bangladesh", ID = "300003" });
this.AutoDataSource = c; //list to autodatasource
this.ShipCountry.DataSource = c;
ShipCountry.DataTextField = "text";
ShipCountry.DataUniqueKeyField = "ID";
ShipCountry.DataBind();
}
protected void EditEvents_ServerEditRow(object sender, GridEventArgs e)
{
var item = this.autoComp.Value;
JavaScriptSerializer mySerialiser = new JavaScriptSerializer();
var data = mySerialiser.Deserialize<object>(item); // empty records
EditAction(e.EventType, e.Arguments["data"]);
}
// WebForm2.aspx -design view
<asp:HiddenField runat="server" ID="autoComp" ClientIDMode="Static" />
<script type="text/template" id="template">
<input id="ShipCountry1" name="ShipCountry" class="e-field e-ejinputtext valid"
style="width: 116px; height: 28px" value="{{:ShipCountry}}" />
</script>
if ((args.requestType == "beginedit" || args.requestType == "add") && args.model.editSettings.editMode == "dialogtemplate") {
var data1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.AutoDataSource)%>');
var data = ej.DataManager(data1).executeLocal(new ej.Query().select("ID", "text"));
$("#ShipCountry1").ejAutocomplete({
width: "100%",
dataSource: data,
fields: { text: "text", key: "ID" },
select: function (argument) {
$("#autoComp").val(JSON.stringify(argument.item));
},
enableDistinct: true
});
}
Thanks
Pratheep
var data1 = JSON.parse('[{"text":"Austria","ID":"100001"},{"text":"Australia","ID":"20002"},{"text":"Bangladesh","ID":"300003"}]'); |
[WebForm2.aspx.cs] … public IEnumerable AutoDataSource; … protected void Page_Load(object sender, EventArgs e) { BindDataSource(); bindcountry(); Session["DialogDataSource"] = order; } private void 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 = "Bangladesh", ID = "300003" }); this.AutoDataSource = c; this.ShipCountry.DataSource = c; ShipCountry.DataTextField = "text"; ShipCountry.DataUniqueKeyField = "ID"; ShipCountry.DataBind(); } |
… <asp:HiddenField runat="server" ID="autoComp" ClientIDMode="Static" /> … function complete(args) { $("#ShipCountry1").ejAutocomplete({ width: "100%", dataSource: data, fields: { text: "text", key: "ID" }, select: function (argument) { $("#autoComp").val(JSON.stringify(argument.item)); }, enableDistinct: true }); } |
protected void EditEvents_ServerEditRow(object sender, GridEventArgs e) { var item = this.autoComp.Value; JavaScriptSerializer mySerialiser = new JavaScriptSerializer(); var data = mySerialiser.Deserialize<object>(item); // empty EditAction(e.EventType, e.Arguments["data"]); } |