EXTSHARP:Visual Studio 2005 集成EXTJS 插件!最新实例(半天测试)
这些天有空,就看了看ajax框架的信息,当我注意到dojochina时,我开始接触到的是dojo,给我的第一感觉是,很简结,效果也不错,当我看了一天的dojo后,试了一把(只是界面上的,没有用数据进行测试),当然有些效果还是出来了,也有些效果bug有点多(如:dnd);后来钟跟我说EXT用的比较好,那我就看了下extjs,因为例子都比较清楚,效果真的很不错,我决定试一下这个EXTJS,后来直接拿数据测试,下面是JS代码:
ds: new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: "http://localhost:2216/DojoAndExt/Demo/App/App_GridUsers.aspx"
// url: "App/XMLFile.xml"
}),
reader: new Ext.data.XmlReader({
record:"user"
}, [{name:"UserID", mapping: "UserID"},
{name:"UserName", mapping: "UserName"},
{name:"Gender" , mapping:"Gender"},
{name:"Birthday" , mapping:"Birthday"},
{name:"Department" , mapping:"Department"},
{name:"Note" , mapping:"Note"}])
}),
cm: new Ext.grid.ColumnModel([
{header: "用户名称", width: 300, dataIndex: "UserID"},
{header: "性别", width: 50, dataIndex: "Gender"},
{header: "出生年月", width: 130, dataIndex: "Birthday" , renderer: function(_value){
var _date = new Date(_value) ;
return _date.format("Y-m-d");
}}
]),
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),//sm是Grid的选定模式对象 包含了对于Grid的所有选定方法 ,singleSelect:true是只能单选。。
renderTo:"example_grid",
width:500,
height:300,
loadMask: true
});
_grid.getStore().load();
App_GridUsers.aspx页面的取数据方法:
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
//Response.Write("\n");
using(SqlConnection conn = new SqlConnection("server=.;database=Test;uid=sa;pwd="))
{
SqlCommand cmd = new SqlCommand("select * from users",conn);
DataTable dt = new DataTable("user");
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
writerXML(dt);
//for (int i = 0; i < dt.Rows.Count; i++)
//{
// if (i == dt.Rows.Count - 1)
// {
// Response.Write("[\"" + dt.Rows[i][0] + "\",\"" + dt.Rows[i][1] + "\",\"" + dt.Rows[i][2] + "\",\"" + dt.Rows[i][3] + "\"," + dt.Rows[i][4] + ",\"" + dt.Rows[i][5] + "\",\"" + dt.Rows[i][6] + "\"]");
// Response.Write("\n");
// }
// else
// {
// Response.Write("[\"" + dt.Rows[i][0] + "\",\"" + dt.Rows[i][1] + "\",\"" + dt.Rows[i][2] + "\",\"" + dt.Rows[i][3] + "\"," + dt.Rows[i][4] + ",\"" + dt.Rows[i][5] + "\",\"" + dt.Rows[i][6] + "\"],");
// Response.Write("\n");
// }
//}
}
}
/// <summary>
/// XML转换
/// </summary>
/// <param name="dt"></param>
public void writerXML(DataTable dt)
{
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();//XML文件头;
//writer.Indentation = 4;
//writer.IndentChar = ' ';
dt.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
注:当我把url改成xml文件地址时,数据出现了,可换成aspx页面时,数据出不来(选择的是绝对路径,怕路径有问题...当然,这个页面出来的数据跟xml数据是完全一样的..(xml文件是页面出来后copy出来添加的xml文件))..这样两个数据一模一样,但页面数据显示不出来..真是莫名其妙....
哎有点想放弃ext..今天早上再次看一下Ext用在VS2005上的插件(本人用的是.net)...http://www.dojochina.com/?q=node/471这个贴子后,找到了google官方最新的VS2005上的例子http://code.google.com/p/extsharp/,在他列表里(http://code.google.com/p/extsharp/downloads/list)下载了里面的两个例子(这两个例子也就发布了一天时间)和一个安装包,(script#,非得安装这个包,)装完后,
在打开解决方案时出现了一点问题,可能是google发布时没考虑到targets..在解决方案里是这个路径..( <Import Project="$(ProgramFiles)\nStuff\ScriptSharp\v1.0\nStuff.ScriptSharp.targets" />),
我从新创建了一个项目,把他所在项目里的文件移植过来了..OK,页面跑进来了..(以前他是写在js文件里...现在是写在CS文件里)效果和js的效果一样...
ext例子还是和以前一样..都是虚数据:
new object[] {"3m Co",71.72,0.02,0.03,"9/1 12:00am"},
new object[] {"Alcoa Inc",29.01,0.42,1.47,"9/1 12:00am"},
new object[] {"Altria Group Inc",83.81,0.28,0.34,"9/1 12:00am"},
new object[] {"American Express Company",52.55,0.01,0.02,"9/1 12:00am"},
new object[] {"American International Group, Inc.",64.13,0.31,0.49,"9/1 12:00am"},
new object[] {"AT&T Inc.",31.61,-0.48,-1.54,"9/1 12:00am"},
new object[] {"Boeing Co.",75.43,0.53,0.71,"9/1 12:00am"},
new object[] {"Caterpillar Inc.",67.27,0.92,1.39,"9/1 12:00am"},
new object[] {"Citigroup, Inc.",49.37,0.02,0.04,"9/1 12:00am"},
new object[] {"E.I. du Pont de Nemours and Company",40.48,0.51,1.28,"9/1 12:00am"},
new object[] {"Exxon Mobil Corp",68.1,-0.43,-0.64,"9/1 12:00am"},
然后我将本地数据库数据通过另外的CS文件以DataTable(VS里DataTable可以转xml)的形式读取出来,
DataTable dt = SampleDAL.DisposeDAL.GetCompanyInfo();//我的数据来源
private object[] GetMyData()
{
object mydata = new object[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
mydata[i] = new object[] { dt.Rows[i][1], dt.Rows[i][2], dt.Rows[i][3], dt.Rows[i][4] };
}
return mydata;
..
}数据结构完全一样吧...(DataTable是VS里system.data下的类型)在重新生成的时候,问题出来了...
错误 2 类型“System.Object”在未被引用的程序集中定义。必须添加对程序集“mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。 E:\MyZone\电子档\Ajax开发工具及学习方法\demo\ExtJS2Samples\SampleScripts\grid\ArrayGridScript.cs 107 19 SampleScripts
我按照提示,将mscorlib这个程序集加到了项目里...
再次重新编译...
错误 92 类型“System.DateTime”同时存在于“c:\Program Files\nStuff\ScriptSharp\v1.0\Framework\sscorlib.dll”和“c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll”中 E:\MyZone\电子档\Ajax开发工具及学习方法\demo\ExtJS2Samples\SampleScripts\view\DataViewScript.cs 17 10 SampleScripts
此时,我完全傻了眼...因为在WEB(页面所以的项目)里有sscorlib.dll个生成好的文件,也就是google所谓的插件..这个插件通过script#语言,将javascript改成了CS里面的类...
在我所测试的CS(以前的js改写的)文件上方看到了这样的代码:
public delegate object ColumnRenderer(object val);
public delegate string MoneyRenderer(string val);
google将VS里的类型改写成了他自己格式的类型...
也就是我前面出的问题
类型“System.DateTime”同时存在于“...两个DLL文件里..当然不只是DateTime..还有别的类型...如果这样的话..那不事倍功半???调用数据之前还要先声明数据类型 ,这个类型还不能是MS的数据类型......
经过两次数据测试..我绝望了...可能是我VS玩的不够好...对sciprt#一点都不了解..当然,也希望EXt再出新的实例的时候,带上数据库...
ds: new Ext.data.Store({
proxy: new Ext.data.HttpProxy({
url: "http://localhost:2216/DojoAndExt/Demo/App/App_GridUsers.aspx"
// url: "App/XMLFile.xml"
}),
reader: new Ext.data.XmlReader({
record:"user"
}, [{name:"UserID", mapping: "UserID"},
{name:"UserName", mapping: "UserName"},
{name:"Gender" , mapping:"Gender"},
{name:"Birthday" , mapping:"Birthday"},
{name:"Department" , mapping:"Department"},
{name:"Note" , mapping:"Note"}])
}),
cm: new Ext.grid.ColumnModel([
{header: "用户名称", width: 300, dataIndex: "UserID"},
{header: "性别", width: 50, dataIndex: "Gender"},
{header: "出生年月", width: 130, dataIndex: "Birthday" , renderer: function(_value){
var _date = new Date(_value) ;
return _date.format("Y-m-d");
}}
]),
sm: new Ext.grid.RowSelectionModel({singleSelect:true}),//sm是Grid的选定模式对象 包含了对于Grid的所有选定方法 ,singleSelect:true是只能单选。。
renderTo:"example_grid",
width:500,
height:300,
loadMask: true
});
_grid.getStore().load();
App_GridUsers.aspx页面的取数据方法:
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
//Response.Write("\n");
using(SqlConnection conn = new SqlConnection("server=.;database=Test;uid=sa;pwd="))
{
SqlCommand cmd = new SqlCommand("select * from users",conn);
DataTable dt = new DataTable("user");
SqlDataAdapter da = new SqlDataAdapter(cmd);
da.Fill(dt);
writerXML(dt);
//for (int i = 0; i < dt.Rows.Count; i++)
//{
// if (i == dt.Rows.Count - 1)
// {
// Response.Write("[\"" + dt.Rows[i][0] + "\",\"" + dt.Rows[i][1] + "\",\"" + dt.Rows[i][2] + "\",\"" + dt.Rows[i][3] + "\"," + dt.Rows[i][4] + ",\"" + dt.Rows[i][5] + "\",\"" + dt.Rows[i][6] + "\"]");
// Response.Write("\n");
// }
// else
// {
// Response.Write("[\"" + dt.Rows[i][0] + "\",\"" + dt.Rows[i][1] + "\",\"" + dt.Rows[i][2] + "\",\"" + dt.Rows[i][3] + "\"," + dt.Rows[i][4] + ",\"" + dt.Rows[i][5] + "\",\"" + dt.Rows[i][6] + "\"],");
// Response.Write("\n");
// }
//}
}
}
/// <summary>
/// XML转换
/// </summary>
/// <param name="dt"></param>
public void writerXML(DataTable dt)
{
XmlTextWriter writer = new XmlTextWriter(Response.OutputStream, Response.ContentEncoding);
writer.Formatting = Formatting.Indented;
writer.WriteStartDocument();//XML文件头;
//writer.Indentation = 4;
//writer.IndentChar = ' ';
dt.WriteXml(writer);
writer.Flush();
Response.End();
writer.Close();
}
注:当我把url改成xml文件地址时,数据出现了,可换成aspx页面时,数据出不来(选择的是绝对路径,怕路径有问题...当然,这个页面出来的数据跟xml数据是完全一样的..(xml文件是页面出来后copy出来添加的xml文件))..这样两个数据一模一样,但页面数据显示不出来..真是莫名其妙....
哎有点想放弃ext..今天早上再次看一下Ext用在VS2005上的插件(本人用的是.net)...http://www.dojochina.com/?q=node/471这个贴子后,找到了google官方最新的VS2005上的例子http://code.google.com/p/extsharp/,在他列表里(http://code.google.com/p/extsharp/downloads/list)下载了里面的两个例子(这两个例子也就发布了一天时间)和一个安装包,(script#,非得安装这个包,)装完后,
在打开解决方案时出现了一点问题,可能是google发布时没考虑到targets..在解决方案里是这个路径..( <Import Project="$(ProgramFiles)\nStuff\ScriptSharp\v1.0\nStuff.ScriptSharp.targets" />),
我从新创建了一个项目,把他所在项目里的文件移植过来了..OK,页面跑进来了..(以前他是写在js文件里...现在是写在CS文件里)效果和js的效果一样...
ext例子还是和以前一样..都是虚数据:
new object[] {"3m Co",71.72,0.02,0.03,"9/1 12:00am"},
new object[] {"Alcoa Inc",29.01,0.42,1.47,"9/1 12:00am"},
new object[] {"Altria Group Inc",83.81,0.28,0.34,"9/1 12:00am"},
new object[] {"American Express Company",52.55,0.01,0.02,"9/1 12:00am"},
new object[] {"American International Group, Inc.",64.13,0.31,0.49,"9/1 12:00am"},
new object[] {"AT&T Inc.",31.61,-0.48,-1.54,"9/1 12:00am"},
new object[] {"Boeing Co.",75.43,0.53,0.71,"9/1 12:00am"},
new object[] {"Caterpillar Inc.",67.27,0.92,1.39,"9/1 12:00am"},
new object[] {"Citigroup, Inc.",49.37,0.02,0.04,"9/1 12:00am"},
new object[] {"E.I. du Pont de Nemours and Company",40.48,0.51,1.28,"9/1 12:00am"},
new object[] {"Exxon Mobil Corp",68.1,-0.43,-0.64,"9/1 12:00am"},
然后我将本地数据库数据通过另外的CS文件以DataTable(VS里DataTable可以转xml)的形式读取出来,
DataTable dt = SampleDAL.DisposeDAL.GetCompanyInfo();//我的数据来源
private object[] GetMyData()
{
object mydata = new object[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
mydata[i] = new object[] { dt.Rows[i][1], dt.Rows[i][2], dt.Rows[i][3], dt.Rows[i][4] };
}
return mydata;
..
}数据结构完全一样吧...(DataTable是VS里system.data下的类型)在重新生成的时候,问题出来了...
错误 2 类型“System.Object”在未被引用的程序集中定义。必须添加对程序集“mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089”的引用。 E:\MyZone\电子档\Ajax开发工具及学习方法\demo\ExtJS2Samples\SampleScripts\grid\ArrayGridScript.cs 107 19 SampleScripts
我按照提示,将mscorlib这个程序集加到了项目里...
再次重新编译...
错误 92 类型“System.DateTime”同时存在于“c:\Program Files\nStuff\ScriptSharp\v1.0\Framework\sscorlib.dll”和“c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll”中 E:\MyZone\电子档\Ajax开发工具及学习方法\demo\ExtJS2Samples\SampleScripts\view\DataViewScript.cs 17 10 SampleScripts
此时,我完全傻了眼...因为在WEB(页面所以的项目)里有sscorlib.dll个生成好的文件,也就是google所谓的插件..这个插件通过script#语言,将javascript改成了CS里面的类...
在我所测试的CS(以前的js改写的)文件上方看到了这样的代码:
public delegate object ColumnRenderer(object val);
public delegate string MoneyRenderer(string val);
google将VS里的类型改写成了他自己格式的类型...
也就是我前面出的问题
类型“System.DateTime”同时存在于“...两个DLL文件里..当然不只是DateTime..还有别的类型...如果这样的话..那不事倍功半???调用数据之前还要先声明数据类型 ,这个类型还不能是MS的数据类型......
经过两次数据测试..我绝望了...可能是我VS玩的不够好...对sciprt#一点都不了解..当然,也希望EXt再出新的实例的时候,带上数据库...