public IEnumerable SqlDataSource; List<Employees> emp = new List<Employees>(); protected void Page_Load(object sender, EventArgs e) { this.EmployeesGrid.DataSource = emp; this.EmployeesGrid.DataBind(); //this.childData a SQLDataSource defined at the client-end used to retrieve the data in code behind. DataView dv = (DataView)this.childData.Select(DataSourceSelectArguments.Empty); DataTable dt1 = dv.ToTable(); IEnumerable Data = (from DataRow row in dt1.Rows select new Order { OrderID = Convert.ToInt32(row["OrderID"]), CustomerID = row["CustomerID"].ToString(), Freight = Convert.ToDecimal(row["Freight"]), EmployeeID = Convert.ToInt32(row["EmployeeID"]), ShipCity = row["ShipCity"].ToString(), ShipCountry = row["ShipCountry"].ToString() }).ToList(); this.SqlDataSource = Data; } <ej:Grid ID="EmployeesGrid" runat="server" DetailsTemplate="#tabGridContents"> <ClientSideEvents DetailsDataBound="detailGridData" /> . . . . . . . . </ej:Grid> <asp:SqlDataSource id="childData" runat="server" ConnectionString="<%$ ConnectionStrings:SQLConnectionString%>" SelectCommand="SELECT * FROM Orders"> </asp:SqlDataSource> <script id="tabGridContents" type="text/x-jsrender"> . . </script> <script type="text/javascript"> //SqlDataSource a variable defined at the code behind var orderData = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.SqlDataSource)%>'); function detailGridData(e) { var filteredData = e.data["EmployeeID"]; var data = ej.DataManager(orderData).executeLocal(ej.Query().where("EmployeeID", "equal", parseInt(filteredData), true)); e.detailsElement.find("#detailGrid" + filteredData).ejGrid({ dataSource: data, allowSelection: false, allowPaging: true, . . . . }); e.detailsElement.css("display", ""); e.detailsElement.find("#detailChart" + filteredData).ejChart({ . . . . . }); e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 }); } </script> |
<ej:Grid ID="EmployeesGrid" runat="server" DetailsTemplate="#tabGridContents">
<ClientSideEvents DetailsDataBound="detailGridData" />
. . .
. . .
</ej:Grid>
<asp:SqlDataSource
id="childData"
runat="server"
ConnectionString="<%$ ConnectionStrings:SQLConnectionString%>"
SelectCommand="SELECT * FROM Orders">
</asp:SqlDataSource>
. . . .
. . .
<script id="tabGridContents" type="text/x-jsrender">
<div class="tabcontrol">
<ul>
<li><a rel='nofollow' href="#gridTab1{{:EmployeeID}}">Stock Chart</a>
</li>
<li><a rel='nofollow' href="#gridTab2{{:EmployeeID}}">Stock Grid</a>
</li>
<li><a rel='nofollow' href="#gridTab3{{:EmployeeID}}">Stock Grid</a>
</li>
</ul>
<div id="gridTab1{{:EmployeeID}}">
<div id="detailGrid1{{:EmployeeID}}"></div>
</div>
<div id="gridTab2{{:EmployeeID}}">
<div id="detailGrid2{{:EmployeeID}}"></div>
</div>
<div id="gridTab3{{:EmployeeID}}">
<div id="detailGrid3{{:EmployeeID}}"></div>
</div>
</div>
</script>
<script type="text/javascript">
//SqlDataSource a variable defined at the code behind
var orderData1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.SqlDataSource1)%>');
var orderData2 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.SqlDataSource2)%>');
var orderData3 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.SqlDataSource3)%>');
function detailGridData(e) {
var filteredData = e.data["EmployeeID"];
var data1 = ej.DataManager(orderData1).executeLocal(ej.Query().where("EmployeeID", "equal", parseInt(filteredData), true));
. . . .
. .
e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({
dataSource: data1,
allowSelection: false,
allowPaging: true,
. . . .
});
e.detailsElement.find("#detailGrid2" + filteredData).ejGrid({
dataSource: data2,
});
e.detailsElement.find("#detailGrid3" + filteredData).ejGrid({
dataSource: data3,
});
e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 });
}
</script> |
public IEnumerable SqlDataSource1;
public IEnumerable SqlDataSource2;
public IEnumerable SqlDataSource3;
List<Employees> emp = new List<Employees>();
List<Orders> order = new List<Orders>();
protected void Page_Load(object sender, EventArgs e)
{
. . .
.. . . .
DataView dv = (DataView)this.childData.Select(DataSourceSelectArguments.Empty);
DataView dv1 = (DataView)this.childData1.Select(DataSourceSelectArguments.Empty);
DataView dv2 = (DataView)this.childData2.Select(DataSourceSelectArguments.Empty);
DataTable dt = dv.ToTable();
DataTable dt1 = dv1.ToTable();
DataTable dt2 = dv2.ToTable();
this.SqlDataSource1 = ToDynamicList(dt);
this.SqlDataSource2 = ToDynamicList(dt1);
this.SqlDataSource3 = ToDynamicList(dt2);
}
public List<dynamic> ToDynamicList(DataTable dt)
{
List<string> cols = (dt.Columns.Cast<DataColumn>()).Select(column => column.ColumnName).ToList();
var dictData = ToDictionary(dt);
return ToDynamicList(dictData, getNewObject(cols, dictData));
}
public List<dynamic> ToDynamicList(List<Dictionary<string, object>> list, Type TypeObj)
{
dynamic temp = new List<dynamic>();
foreach (Dictionary<string, object> step in list)
{
object Obj = Activator.CreateInstance(TypeObj);
PropertyInfo[] properties = Obj.GetType().GetProperties();
Dictionary<string, object> DictList = (Dictionary<string, object>)step;
foreach (KeyValuePair<string, object> keyValuePair in DictList)
{
foreach (PropertyInfo property in properties)
{
if (property.Name == keyValuePair.Key)
{
var convertedValue = keyValuePair.Value == System.DBNull.Value ? null : keyValuePair.Value;
property.SetValue(Obj, convertedValue, null);
break;
}
}
}
temp.Add(Obj);
}
return temp;
}
public List<Dictionary<string, object>> ToDictionary(DataTable dt)
{
var columns = dt.Columns.Cast<DataColumn>();
var Temp = dt.AsEnumerable().Select(dataRow => columns.Select(column =>
new { Column = column.ColumnName, Value = dataRow[column] })
.ToDictionary(data => data.Column, data => data.Value)).ToList();
return Temp.ToList();
}
private Type getNewObject(List<string> list, List<Dictionary<string, object>> dictList)
{ .. .
. . . .
bool flag = true;
if (flag)
{
foreach (Dictionary<string, object> dictStep in dictList)
{
flag = false;
Dictionary<string, object> DictList = (Dictionary<string, object>)dictStep;
foreach (KeyValuePair<string, object> keyValuePair in DictList)
{
var type = keyValuePair.Value.GetType().ToString();
colType.Add(type);
}
}
}
foreach (string step in list)
{
int inx = list.IndexOf(step);
var type = colType[inx];
string propertyName = step;
. . . .
}
Type obj = typeBuilder.CreateType();
return obj;
} |
<ej:Grid ID="EmployeesGrid" runat="server" DetailsTemplate="#tabGridContents">
<ClientSideEvents DetailsDataBound="detailGridData" />
. ..
. .
</ej:Grid>
<script id="tabGridContents" type="text/x-jsrender">
<div class="tabcontrol">
<ul>
<li><a rel='nofollow' href="#gridTab1{{:EmployeeID}}">Stock Chart</a>
</li>
</ul>
<div id="gridTab1{{:EmployeeID}}">
<button id="btn{{:EmployeeID}}"></button>
<div id="detailGrid1{{:EmployeeID}}"></div>
</div>
</div>
</script>
<script type="text/javascript">
//SqlDataSource a variable defined at the code behind
var orderData1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.SqlDataSource1)%>');
function detailGridData(e) {
var filteredData = e.data["EmployeeID"];
var data1 = ej.DataManager(orderData1).executeLocal(ej.Query().where("EmployeeID", "equal", parseInt(filteredData), true));
e.detailsElement.find("#btn" + filteredData).ejButton({
text: "ClickMe"
});
e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({
dataSource: data1,
allowSelection: false,
allowPaging: true,
});
. . .
. . .
e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 });
}
</script> |
<configuration>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="50000000"/>
</webServices>
</scripting>
</system.web.extensions>
</configuration>
|
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object Data(Syncfusion.JavaScript.DataManager value)
{
IEnumerable Data = Data1; //it is a Dynamically created data
DataOperations dp = new DataOperations();
if (value.Where != null)
{
Data = dp.PerformWhereFilter(Data, value.Where, value.Where[0].Condition);
}
int count = Data.AsQueryable().Count();
if (value.Skip != null)
Data = dp.PerformSkip(Data, value.Skip);
if (value.Take != null)
Data = dp.PerformTake(Data, value.Take);
return new { result = Data, count = count };
}
function detailGridData(e) {
var filteredData = e.data["EmployeeID"];
e.detailsElement.find("#btn" + filteredData).ejButton({
text: "ClickMe"
});
e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({
dataSource: ej.DataManager({ url: "Default.aspx/Data", adaptor: new ej.WebMethodAdaptor() }),
query: ej.Query().where("EmployeeID", "equal", parseInt(filteredData), true),
allowPaging: true,
load: function (args) {
this.model.dataSource.dataSource.headers = [];//So define them as array
this.model.dataSource.dataSource.headers.push({ "ID": this._id });//
},
});
. . .
. ..
e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 });
} |
<script type="text/javascript"> //SqlDataSource a variable defined at the code behind var orderData1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.SqlDataSource1)%>'); var data1 = ej.DataManager(orderData1).executeLocal(ej.Query().where("CustomerID", "equal", parseInt(filteredData), true)); function detailGridData(e) { var filteredData = e.data["EmployeeID"]; e.detailsElement.find("#btn" + filteredData).ejButton({ text: "ClickMe" }); e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({ dataSource: data1, . .. }); .. . .. . e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 }); } </script> </asp:Content> |
<configuration>
<configSections>
. . .
</connectionStrings>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="500000000" />
</webServices>
</scripting>
</system.web.extensions>
. ..
. .
</configuration> |
<script type="text/javascript">
//SqlDataSource a variable defined at the code behind
var orderData1 = JSON.parse('<%= new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(this.SqlDataSource1)%>');
function detailGridData(e) {
var filteredData = e.data["EmployeeID"];
var data1 = ej.DataManager(orderData1).executeLocal(ej.Query().where("EmployeeID", "equal", parseInt(filteredData), true));
. . .
..
e.detailsElement.find("#btn" + filteredData).ejButton({
text: "ClickMe"
});
e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({
dataSource: data1,
allowSelection: false,
allowPaging: true,
. .. .
. . .
});
. ..
. ..
e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 });
}
</script>
</asp:Content>
|
hi! i0m again here. The solution will run correctly, but i have a big problem. For my child dataource, i have a query with more join and field, then it have more rec ord: if i write to 500 recordr, all run, but as i get over 500 record, such us 1000 the Json Serialize problem will appear again. Then, i have read there is a solution for that, using paging of grid and rewrite json specification. In my case, what is the solution?
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<ej:Grid ID="EmployeesGrid" runat="server" DetailsTemplate="#tabGridContents">
<ClientSideEvents DetailsDataBound="detailGridData" />
. ..
.. .
</ej:Grid>
<asp:SqlDataSource
id="childData"
runat="server"
ConnectionString="<%$ ConnectionStrings:SQLConnectionString%>"
SelectCommand="SELECT * FROM Orders">
</asp:SqlDataSource>
. . . .
<script type="text/javascript">
function detailGridData(e) {
var filteredData = e.data["EmployeeID"];
e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({
dataSource: ej.DataManager({
url: "Default.aspx/DataSource",
adaptor: new ej.WebMethodAdaptor()
}),
allowPaging: true,
query: new ej.Query().where("EmployeeID", "equal", parseInt(filteredData)),
. .
..
});
. .
..
e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 });
}
</script>
</asp:Content>
public partial class _Default : Page
{
public static IEnumerable Data1;
List<Employees> emp = new List<Employees>();
protected void Page_Load(object sender, EventArgs e)
{
this.EmployeesGrid.DataSource = emp;
this.EmployeesGrid.DataBind();
DataView dv = (DataView)this.childData.Select(DataSourceSelectArguments.Empty);
DataTable dt = dv.ToTable();
JavaScriptSerializer serializer = new JavaScriptSerializer();
List<Dictionary<string, object>> dictData = ToDictionary(dt);
//Creating Table Type
Type tableType = GetTableType(dictData);
var inst = Array.CreateInstance(tableType, 1);
//Converting to JSON String
string str = DataTableToJSONWithJavaScriptSerializer(dt);
//Generating Deserialized data
Data1 = serializer.Deserialize(str, inst.GetType()) as object[];
}
public string DataTableToJSONWithJavaScriptSerializer(DataTable table)
{
. .
. .
return jsSerializer.Serialize(parentRow);
}
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object DataSource(Syncfusion.JavaScript.DataManager value)
{
IEnumerable Data = Data1;
DataOperations dp = new DataOperations();
if (value.Where != null)
{
Data = dp.PerformWhereFilter(Data, value.Where, value.Where[0].Condition);
}
int count = Data.AsQueryable().Count();
if (value.Skip != null)
Data = dp.PerformSkip(Data, value.Skip);
if (value.Take != null)
Data = dp.PerformTake(Data, value.Take);
return new { result = Data, count = count };
}
public List<Dictionary<string, object>> ToDictionary(DataTable dt)
{
var columns = dt.Columns.Cast<DataColumn>();
var Temp = dt.AsEnumerable().Select(dataRow => columns.Select(column =>
new { Column = column.ColumnName, Value = dataRow[column] })
.ToDictionary(data => data.Column, data => data.Value)).ToList();
return Temp.ToList();
}
public static Type GetTableType(List<Dictionary<string, object>> dictList)
{
// Create needed TypeBuilder helpers
. ..
. .
return myTypeBuilder.CreateType();
}
}
|
hi, i have a problem, the solution not run!seems, that the function Datasoure, on url, not called on stack of javascript... the page not apper nothing data on detailed but the wheel continusly turns without apper data.maybe the url is wrong? I haver write: Default2.aspx/DataSource because ,y page called Default2.
hi, i have a problem, the solution not run!seems, that the function Datasoure, on url, not called on stack of javascript... the page not apper nothing data on detailed but the wheel continusly turns without apper data.maybe the url is wrong? I haver write: Default2.aspx/DataSource because ,y page called Default2.
in other, the javascript error apperar seems when i put all date.
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object DataSource(Syncfusion.JavaScript.DataManager value)
{
IEnumerable Data = SqlDataSource1;
DataOperations dp = new DataOperations();
List<FilteredColumn> fColList = new List<FilteredColumn>();
if (value.Where != null)
{
Data = dp.PerformWhereFilter(Data, value.Where, value.Where[0].Condition);
}
int count = Data.AsQueryable().Count();
if (value.Skip != null)
Data = dp.PerformSkip(Data, value.Skip);
if (value.Take != null)
Data = dp.PerformTake(Data, value.Take);
return new { result = Data, count = count };
} |
<script type="text/javascript"> function detailGridData(e) { var filteredData = e.data["IDPOLIZZA"]; e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({ dataSource: ej.DataManager({ url: "Default2.aspx/DataSource", adaptor: new ej.WebMethodAdaptor() }), allowPaging: true, query: new ej.Query().where("IDPOLIZZA", "equal", parseInt(filteredData)), }); e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 }); } </script> public static class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { var settings = new FriendlyUrlSettings(); // settings.AutoRedirectMode = RedirectMode.Permanent; remove this line routes.EnableFriendlyUrls(settings); } } |
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object DataSource(Syncfusion.JavaScript.DataManager value)
{
. . .
if (value.Skip != null)
Data = dp.PerformSkip(Data, value.Skip);
if (value.Take != null)
Data = dp.PerformTake(Data, value.Take);
return new { result = Data, count = count };
}
|
i have resolve javascript serialized inserting :serializer.MaxJsonLenght=Int.MaxValue in page load when serailizer and when deserialized. Is right?In other i have another problem, when i execute a filter, and result is one record, when open detail the grid is so small for make see all detailed date, i attach a pics.
Attachment: screen_234df924.rar
e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({
dataSource: ej.DataManager({
url: "Default.aspx/DataSource",
adaptor: new ej.WebMethodAdaptor()
}),
allowPaging: true,
query: new ej.Query().where("EmployeeID", "equal", parseInt(filteredData)),
columns: [
.. . .
. .
{ field: "Freight", headerText: 'Freight', width: 120,format: "{0:C3}" },
{ field: "OrderDate", headerText: 'OrderDate', format: "{0:MM/dd/yyyy}" },
]
}); |
protected void Page_Load(object sender, EventArgs e)
{
DataView dv = (DataView)this.childData.Select(DataSourceSelectArguments.Empty);
DataTable dt = dv.ToTable();
List<Dictionary<string, object>> dictData = ToDictionary(dt);
//Creating Table Type
Type tableType = GetTableType(dictData);
var inst = Array.CreateInstance(tableType, 1);
List<string> errors = new List<string>();
//Converting to JSON String
string str = DataTableToJSONWithJavaScriptSerializer(dt);
//replace the JavaScriptSerializer with JsonConvert
SqlDataSource1 = JsonConvert.DeserializeObject(str, inst.GetType(),
new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
}) as object[];
}
public static Type GetTableType(List<Dictionary<string, object>> dictList)
{
// Create needed TypeBuilder helpers
AppDomain myDomain = Thread.GetDomain();
AssemblyName myAsmName = new AssemblyName("Anonymous");
AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(myAsmName, AssemblyBuilderAccess.Run);
ModuleBuilder myModBuilder = myAsmBuilder.DefineDynamicModule(myAsmName.Name);
TypeBuilder myTypeBuilder = myModBuilder.DefineType("TestClass", TypeAttributes.Public);
Dictionary<string, object> DictList = (Dictionary<string, object>)dictList[0];
foreach (KeyValuePair<string, object> keyValuePair in DictList)
{
var type = keyValuePair.Value.GetType().ToString();
Type PropertyType;
var PropertyName = keyValuePair.Key;
PropertyType = Type.GetType(type); //directly assign the property and use them in property/field builder
//refer the attached sample
FieldBuilder PropertyFieldBuilder = myTypeBuilder.DefineField(PropertyName.ToLower(), PropertyType, FieldAttributes.Private);
PropertyBuilder PBuilder = myTypeBuilder.DefineProperty(PropertyName, System.Reflection.PropertyAttributes.HasDefault, PropertyType, null);
. . .
.. .
}
. .
return myTypeBuilder.CreateType();
} |
<script type="text/javascript">
function detailGridData(e) {
var filteredData = e.data["IDPOLIZZA"];
e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({
dataSource: ej.DataManager({
url: "Default2.aspx/DataSource",
adaptor: new ej.WebMethodAdaptor()
}),
allowPaging: true,
query: new ej.Query().where("IDPOLIZZA", "equal", parseInt(filteredData)),
columns: [
. . .
//currency format
{ field: "PASSIVE", headerText: 'PASSIVE', format: "{0:C3}", width: 120, textAlign: ej.TextAlign.Left },
//date format
{ field: "DATA_SCADENZA", headerText: 'DATA_SCADENZA', format: "{0:MM/dd/yyyy}" }
]
});
e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 });
}
</script> |
<script type="text/javascript">
function detailGridData(e) {
var filteredData = e.data["IDPOLIZZA"];
e.detailsElement.find("#detailGrid1" + filteredData).ejGrid({
dataSource: ej.DataManager({
url: "Default2.aspx/DataSource",
adaptor: new ej.WebMethodAdaptor()
}),
allowPaging: true,
. . . .
});
e.detailsElement.find(".tabcontrol").ejTab({ selectedItemIndex: 1 });
}
</script>
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static object DataSource(Syncfusion.JavaScript.DataManager value)
{
IEnumerable Data = SqlDataSource1;
DataOperations dp = new DataOperations();
if (value.Where != null)
{
Data = dp.PerformWhereFilter(Data, value.Where, value.Where[0].Condition);
}
int count = Data.AsQueryable().Count();
if (value.Skip != null)
Data = dp.PerformSkip(Data, value.Skip);
if (value.Take != null)
Data = dp.PerformTake(Data, value.Take);
return new { result = Data, count = count };
} |
<ej:Grid ID="Grid1" runat='server' AllowFiltering="True" AllowPaging="True" AllowResizeToFit="true" >
<Columns>
. . .
</Columns>
</ej:Grid> |
<ej:Grid ID="Grid1" runat='server' AllowPaging="True" AllowScrolling="false"
AllowResizing="false" AllowSelection="true" AllowResizeToFit="true"
IsResponsive="True" MinWidth="500" Locale="it-IT" >
<ScrollSettings Width="1000" EnableTouchScroll="true" ></ScrollSettings>
. . .
</ej:Grid>
|
Site.master page
<head runat="server">
<meta charset="utf-8" />
. . .
<link rel='nofollow' href="Content/ej/web/flat-lime/ej.widgets.all.min.css" rel="stylesheet" />
<link rel='nofollow' href="Content/ej/web/responsive-css/ejgrid.responsive.css" rel="stylesheet" />
. .
<script src="Scripts/ej/ej.web.all.min.js"></script>
</head>
|
<script type="text/x-jsrender" id="buttonTemplate"> <button class="Details" name="Details" title="Vis faktura">Details</button> </script> <ej:Grid ID="FlatGrid" runat="server" OnServerRecordClick="onClick" AllowSorting="true"> <Columns> . . . . . . <ej:Column HeaderText="Employee Details" Template="#buttonTemplate" /> </Columns> <ClientSideEvents RecordClick="RecordClick"/> </ej:Grid> <script type="text/javascript"> $(function () { $("#MainContent_FlatGrid").on("click", ".Details", function (e) { triggerEvent(e); }); }); function triggerEvent(e) { var obj = $("#MainContent_FlatGrid").data("ejGrid"); var args = { currentTarget: e.currentTarget.name, selectedRecord: obj.getSelectedRecords(), selectedIndex: obj.model.selectedRowIndex }; obj._trigger("recordClick", args); } function RecordClick(e) { if (e.currentTarget != "Details") return false else { triggerEvent(e); } } </script> namespace WebApplication21 { public partial class _Default : Page { protected void Page_Load(object sender, EventArgs e) { this.FlatGrid.DataSource = OrderRepository.GetAllRecords().ToList(); } protected void onClick(object sender, EventArgs e) { var a = this.FlatGrid.Model.SelectedRowIndex; } } } |
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> <ej:Grid ID="Grid2" ClientIDMode="Static" runat='server' AllowFiltering="True" AllowPaging="True" AllowSorting="True" > . . </ej:Grid> </asp:Content> |
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> <ej:Grid ID="Grid2" ClientIDMode="Static" runat='server' AllowFiltering="True" AllowPaging="True" AllowSorting="True" > . . </ej:Grid> </asp:Content> <script type="text/javascript"> $(function () { $("#Grid2").on("click", ".Details", function (e) { triggerEvent(e); }); }); function triggerEvent(e) { var obj = $("#Grid2").data("ejGrid"); . .. } function RecordClick(e) { . . } </script> |
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent"> <ej:Grid ID="Grid2" runat='server' OnServerRecordClick="onClick" AllowFiltering="True" AllowPaging="True" AllowSorting="True" > . . </ej:Grid> </asp:Content> <script type="text/javascript"> $(function () { $("#MainContent_Grid2").on("click", ".Details", function (e) { triggerEvent(e); }); }); function triggerEvent(e) { var obj = $("#MainContent_Grid2").data("ejGrid"); . . } function RecordClick(e) { . . } </script> |
<ej:Grid ID="Grid2" runat='server' OnServerRecordClick="onClick" > <ClientSideEvents DetailsDataBound="detailGridData" RecordClick="RecordClick"/> . . . .. . </ej:Grid> <script type="text/javascript"> $(function () { . . . . .. }); function triggerEvent(e) { var obj = $("#MainContent_Grid2").data("ejGrid"); var args = { currentTarget: e.currentTarget.name, selectedRecord: obj.getSelectedRecords()[0], selectedIndex: obj.model.selectedRowIndex }; obj._trigger("recordClick", args); } function RecordClick(e) { . . } </script> protected void onClick(object sender, GridEventArgs e) { object record = e.Arguments["selectedRecord"]; Dictionary<string, object> KeyVal = record as Dictionary<string, object>; foreach (KeyValuePair<string, object> keyval in KeyVal) { if (keyval.Key == "IDPOLIZZA") { . . } } } |
public static IEnumerable<object> SqlDataSource1; protected void Page_Load(object sender, EventArgs e) { //Getting data from the SQLDataSource DataView dv = (DataView)this.childData.Select(DataSourceSelectArguments.Empty); //Converting to Data Table DataTable dt = dv.ToTable(); //Converting Dictionary data List<Dictionary<string, object>> dictData = ToDictionary(dt); //Creating Table Type Type tableType = GetTableType(dictData); //Creating instance var inst = Array.CreateInstance(tableType, 1); //Getting the Child DataSource SqlDataSource1 = DataTableToJSONWithJavaScriptSerializer(dt, inst, SqlDataSource1); } public IEnumerable<object> DataTableToJSONWithJavaScriptSerializer(DataTable table, Array inst, IEnumerable<object> dataSource) { JavaScriptSerializer jsSerializer = new JavaScriptSerializer(); List<Dictionary<string, object>> parentRow = new List<Dictionary<string, object>>(); Dictionary<string, object> childRow; foreach (DataRow row in table.Rows) { childRow = new Dictionary<string, object>(); . . . parentRow.Add(childRow); if (parentRow.Count > 1000) { IEnumerable<object> data = null; string str = jsSerializer.Serialize(parentRow); data = JsonConvert.DeserializeObject(str, inst.GetType(), new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }) as object[]; parentRow = new List<Dictionary<string, object>>(); //Concatenating the dataSource if (dataSource != null) dataSource.Concat(data).ToList(); else dataSource = data; } } return dataSource; } |