IEnumerable "<"invention">" invention = from i in DataContext.invention where i.Sharable == true select i
Friday, 23 March 2012
Tuesday, 13 March 2012
Get JsonSting With Caption
public static string GetJSONString(DataTable Dt,DataTable ColumnCaption)
{
string[] StrDc = new string[Dt.Columns.Count];
string HeadStr = string.Empty;
Dt.TableName = "dt";
if (ColumnCaption == null)
{
for (int i = 0; i < Dt.Columns.Count; i++)
{
StrDc[i] = Dt.Columns[i].Caption;
HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\",";
}
}
else
{
for (int i = 0; i < ColumnCaption.Rows.Count; i++)
{
StrDc[i] = ColumnCaption.Rows[i]["CAPTION"].ToString();
HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\",";
}
}
HeadStr = HeadStr.Substring(0, HeadStr.Length - 1);
StringBuilder Sb = new StringBuilder();
Sb.Append("{\"" + Dt.TableName + "\" : [");
for (int i = 0; i < Dt.Rows.Count; i++)
{
string TempStr = HeadStr;
Sb.Append("{");
for (int j = 0; j < Dt.Columns.Count; j++)
{
if (ColumnCaption != null)
{
TempStr = TempStr.Replace(ColumnCaption.Rows[j]["CAPTION"].ToString() + j.ToString() + "¾", Dt.Rows[i][j].ToString());
}
else
{
TempStr = TempStr.Replace(Dt.Columns[j] + j.ToString() + "¾", Dt.Rows[i][j].ToString());
}
}
Sb.Append(TempStr + "},");
}
Sb = new StringBuilder(Sb.ToString().Substring(0, Sb.ToString().Length - 1));
Sb.Append("]}");
return Sb.ToString();
}
Friday, 2 March 2012
DownloadJSON2CSV
<script type="text/javascript">
function DownloadJSON2CSV() {
alert("hi");
var objArray = { "dt": [{ "SRNO": "1", "REPORT_NO": "1109681094", "CONTROL_NO": "", "PACKET_NO": "D226A1B", "SHAPE": "BR"}] }
var array = typeof objArray != 'object' ? JSON.parse(objArray) : objArray;
var str = '';
for (var i = 0; i < array.length; i++) {
var line = '';
for (var index in array[i]) {
if (line != '') line += ','
line += array[i][index];
}
str += line + '\r\n';
}
if (navigator.appName != 'Microsoft Internet Explorer') {
window.open('data:text/csv;charset=utf-8,' + escape(str));
}
else {
var popup = window.open('test.htm', 'csv', '');
popup.document.body.innerHTML = '<pre>' + str + '</pre>';
}
}
</script>
Thursday, 1 March 2012
datatable to json and show html table
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Services;
using System.Net;
using System.Net.Mail;
using System.Text;
using System.IO;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Configuration;
using System.Web.Script.Serialization;
using System.Web.Script.Services;
using System.Collections.Generic;
public partial class jquerypagemethod : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Label1.Text = HiddenField1.Value;
// Session["name"] = "prnay";
}
[System.Web.Script.Services.ScriptMethod(ResponseFormat=ResponseFormat.Json)]
[ System.Web.Services.WebMethod()]
//[System.Web.Script.Services.ScriptMethod()]
//string cateogryID
public static string GetProducts()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Sql"].ConnectionString);
con.Open();
SqlCommand com = new SqlCommand("SELECT top 1 * FROM STOCK ", con);
com.CommandType = CommandType.Text;
SqlDataAdapter ada = new SqlDataAdapter(com);
DataTable objStockDT = new DataTable();
ada.Fill(objStockDT);
//StringBuilder newstring = new StringBuilder();
string my = GetJSONString(objStockDT);
return my;
}
public static string GetJSONString(DataTable Dt)
{
string[] StrDc = new string[Dt.Columns.Count];
string HeadStr = string.Empty;
Dt.TableName = "dt";
for (int i = 0; i < Dt.Columns.Count; i++)
{
StrDc[i] = Dt.Columns[i].Caption;
HeadStr += "\"" + StrDc[i] + "\" : \"" + StrDc[i] + i.ToString() + "¾" + "\",";
}
HeadStr = HeadStr.Substring(0, HeadStr.Length - 1);
StringBuilder Sb = new StringBuilder();
Sb.Append("{\"" + Dt.TableName + "\" : [");
for (int i = 0; i < Dt.Rows.Count; i++)
{
string TempStr = HeadStr;
Sb.Append("{");
for (int j = 0; j < Dt.Columns.Count; j++)
{
TempStr = TempStr.Replace(Dt.Columns[j] + j.ToString() + "¾", Dt.Rows[i][j].ToString());
}
Sb.Append(TempStr + "},");
}
Sb = new StringBuilder(Sb.ToString().Substring(0, Sb.ToString().Length - 1));
Sb.Append("]}");
return Sb.ToString();
}
<script type="text/javascript">
function outputDT(dataTable) {
var headers = [];
var rows = [];
headers.push("<tr>");
for (var name in dataTable[0])
headers.push("<td><b>" + name + "</b></td>");
headers.push("</tr>");
for (var row in dataTable) {
rows.push("<tr>");
for (var name in dataTable[row]) {
rows.push("<td>");
rows.push(dataTable[row][name]);
rows.push("</td>");
}
rows.push("</tr>");
}
var top = "<table border='1'>";
var bottom = "</table>";
return top + headers.join("") + rows.join("") + bottom;
}
</script>
<script type="text/javascript">
$(document).ready(function () {
$("p").click(function () {
alert("hi");
var areaId = 42;
var jqxhr = $.ajax({
type: "POST",
// url: "jquerypagemethod.aspx/GetRegions",
url: "jquerypagemethod.aspx/GetProducts",
// data: "{cateogryID:" + areaId + "}",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
// var json3 = { "dt": [{ "SRNO": "1", "REPORT_NO": "1109681094", "CONTROL_NO": "", "PACKET_NO": "D226A1B", "SHAPE": "BR"}] }
json3 = JSON.parse(data.d);
// alert(json3.dt);
$('#My').append(CreateTableView(json3.dt, "lightPro", true)).fadeIn();
$(outputDT(json3.dt)).appendTo("#Newtable");
}
});
});
});
</script>
Subscribe to:
Posts (Atom)