Customize Ajax Editor Control
using System;using System.Data;
using System.Configuration;
using System.Linq;using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;using AjaxControlToolkit.HTMLEditor;
/// /// Summary description for customEditor
/// /// namespace myControls
{ public class customEditor : Editor
{ public customEditor()
{ // // TODO: Add constructor logic here // }
protected override void FillTopToolbar()
{ TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Bold()); TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Italic()); TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Copy());
TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.Cut());
TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.BulletedList()); TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.FixedBackColor()); TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.FontSize());
} protected override void FillBottomToolbar()
{ BottomToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.DesignMode()); BottomToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.ToolbarButton.PreviewMode());
}
}}
Ajax and jason Enabled customized Grid
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.IO;
using System.Runtime.Serialization;
public partial class AjaxSupport : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// create sample datatable
DataTable dtJSON = new DataTable();
// add test columns to table
dtJSON.Columns.Add("index");
dtJSON.Columns.Add("itemcode");
dtJSON.Columns.Add("price");
// generate random data and add 10 records in temp table
Random randomNo = new Random();
int pagesize = 10;
int pagenum = 1;
if (Request.QueryString.Count > 0)
{
if (Request.QueryString["psize"] != null)
{
pagesize = Convert.ToInt32(Request.QueryString["psize"]);
}
if (Request.QueryString["pnumber"] != null)
{
pagenum = Convert.ToInt32(Request.QueryString["pnumber"]);
}
}
for (int i = 0; i < pagesize; i++) { dtJSON.Rows.Add(i, generateRandomString(5) + "-" + generateRandomString(5), randomNo.Next(99, 500)); }
// GetJson(dtJSON);
// generate JSON string out of the temp datatable and write it in response of the page
// string tmpstr = "{\"r1\":[{\"index\":\"0\",\"itemcode\":\"65fbc-88572\",\"price\":\"182\"},{\"index\":\"1\",\"itemcode\":\"34a50-50083\",\"price\":\"398\"},{\"index\":\"2\",\"itemcode\":\"30a8e-b2f65\",\"price\":\"365\"},{\"index\":\"3\",\"itemcode\":\"00785-7793e\",\"price\":\"290\"},{\"index\":\"4\",\"itemcode\":\"18303-8abd7\",\"price\":\"335\"},{\"index\":\"5\",\"itemcode\":\"fd5e3-4b5e2\",\"price\":\"422\"},{\"index\":\"6\",\"itemcode\":\"c0eb4-2f681\",\"price\":\"369\"},{\"index\":\"7\",\"itemcode\":\"15f08-584e4\",\"price\":\"394\"},{\"index\":\"8\",\"itemcode\":\"e6a2b-3eea4\",\"price\":\"315\"},{\"index\":\"9\",\"itemcode\":\"1134b-1f972\",\"price\":\"253\"}],\"r2\":[{\"PageSize\":\"10\",\"PageNumber\":\"1\",\"TotalRecord\":\"100\"}]}";
// Response.Write(tmpstr);
Response.Write(GetJson(dtJSON, pagesize, pagenum));
Response.Expires = -1;
}
public String GetJson(DataTable dt, int PageSize, int PageNumber)
{
string response = "";
try
{ string datarow = "";
if (dt.Rows.Count > 0 && dt.Columns.Count > 0)
{
for (int row = 0; row < dt.Rows.Count; row++)
{
datarow += "{";
string tmp = "";
for (int col = 0; col < dt.Columns.Count; col++)
{
if (dt.Columns.Count - 1 != col)
{ \
datarow += "\"" + dt.Columns[col].ToString() + "\" :" + "\"" + dt.Rows[row][col].ToString() + "\",";
}
else
{
datarow += "\"" + dt.Columns[col].ToString() + "\":" + "\"" + dt.Rows[row][col].ToString() + "\"";
}
}
if (dt.Rows.Count - 1 != row)
{
datarow += "},";
}
else
{
datarow += "}";
}
} \
int mod = (dt.Rows.Count % PageNumber);
int totalpages = 0;
if (mod > 0)
{
totalpages = (dt.Rows.Count / PageNumber) + 1;
}
else
{
totalpages = (dt.Rows.Count / PageSize);
}
datarow = "{\"r1\" :[" + datarow + "],\"r2\":[{\"PageSize\":\"" + PageSize + "\",\"PageNumber\":\"" + PageNumber + "\",\"TotalRecord\":\"" + dt.Rows.Count + "\",\"TotalPages\":\"" + totalpages + "\"}]}";
response = datarow;
}
}
catch (Exception e)
{
throw;
}
return response;
}
public static string GetJSONString(DataTable Dt)
{
string[] StrDc = new string[Dt.Columns.Count];
string HeadStr = string.Empty;
Dt.TableName = "DummyData";
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();
}
public static string generateRandomString(int length)
{
string randomString = Guid.NewGuid().ToString("N");
randomString = randomString.Substring(0, length);
return randomString;
}
'Using Populate On Demand and AJAX in Treeview
PopulateOnDemand="true" Text="Node 0" />