ÔÚasp.net開發ÖУ¬經³£會Óõ½áą́ºÍǰ̨µÄ½»»¥£¬¾Í´Ë總結ÁËÒ»點c#ºÍjavascriptÏ໥²Ù×÷µÄ·½·¨
¡¡¡¡1.ÔÚáą́c#´ú碼ÖÐ調ÓÃjacascriptµÄ·½·¨
¡¡¡¡javascript´ú碼£º
¡¡¡¡<script type="text/javascript" language="javascript">
¡¡¡¡function test()
¡¡¡¡{
¡¡¡¡alert("oec2003");
¡¡¡¡return false;
¡¡¡¡}
¡¡¡¡</script>
¡¡¡¡c#´ú碼£º
¡¡¡¡protected void Button1_Click(object sender, EventArgs e)
¡¡¡¡{
¡¡¡¡ClientScript.RegisterStartupScript(this.GetType(), "clear", "<script>test()</script>");
¡¡¡¡}
¡¡¡¡2.javascriptÖÐ調ÓÃc#·½·¨
¡¡¡¡Èç¹ûc#Öеķ½·¨Óзµ»ØÖµ£¬¿ÉÒÔÓÃÏÂÃæ·½·¨
¡¡¡¡c#´ú碼
¡¡¡¡public string GetAuthStatus()
¡¡¡¡{
¡¡¡¡ViewState["Auth"] = "Red";
¡¡¡¡return ViewState["Auth"].ToString();
¡¡¡¡}
¡¡¡¡javascript´ú碼
¡¡¡¡function getAuth()
¡¡¡¡{
¡¡¡¡var authStatus="<%=GetAuthStatus()%>";
¡¡¡¡return authStatus;
¡¡¡¡}
¡¡¡¡Èç¹ûÔÚjavascript調ÓõÄc#·½·¨沒Óзµ»ØÖµ£¬¿ÉÒÔÔÚÒ ......
ÔÚasp.net開發ÖУ¬經³£會Óõ½áą́ºÍǰ̨µÄ½»»¥£¬¾Í´Ë總結ÁËÒ»點c#ºÍjavascriptÏ໥²Ù×÷µÄ·½·¨
¡¡¡¡1.ÔÚáą́c#´ú碼ÖÐ調ÓÃjacascriptµÄ·½·¨
¡¡¡¡javascript´ú碼£º
¡¡¡¡<script type="text/javascript" language="javascript">
¡¡¡¡function test()
¡¡¡¡{
¡¡¡¡alert("oec2003");
¡¡¡¡return false;
¡¡¡¡}
¡¡¡¡</script>
¡¡¡¡c#´ú碼£º
¡¡¡¡protected void Button1_Click(object sender, EventArgs e)
¡¡¡¡{
¡¡¡¡ClientScript.RegisterStartupScript(this.GetType(), "clear", "<script>test()</script>");
¡¡¡¡}
¡¡¡¡2.javascriptÖÐ調ÓÃc#·½·¨
¡¡¡¡Èç¹ûc#Öеķ½·¨Óзµ»ØÖµ£¬¿ÉÒÔÓÃÏÂÃæ·½·¨
¡¡¡¡c#´ú碼
¡¡¡¡public string GetAuthStatus()
¡¡¡¡{
¡¡¡¡ViewState["Auth"] = "Red";
¡¡¡¡return ViewState["Auth"].ToString();
¡¡¡¡}
¡¡¡¡javascript´ú碼
¡¡¡¡function getAuth()
¡¡¡¡{
¡¡¡¡var authStatus="<%=GetAuthStatus()%>";
¡¡¡¡return authStatus;
¡¡¡¡}
¡¡¡¡Èç¹ûÔÚjavascript調ÓõÄc#·½·¨沒Óзµ»ØÖµ£¬¿ÉÒÔÔÚÒ ......
ÎÄÕÂÀ´Ô´£ºIT¹¤³Ì¼¼ÊõÍø http://www.systhinker.com/html/43/n-11643.html
ÓõÄÊÇÒ»Öֺܱ¿µÄ·½·¨£¬µ«¿ÉÒÔ°ïÖú³õѧÕßÁ˽â·ÃÎÊXML½ÚµãµÄ¹ý³Ì¡£
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏÂ:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1¡¢Íù<bookstore>½ÚµãÖвåÈëÒ»¸ö<book>½Úµã£º
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//²éÕÒ<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//´´½¨Ò»¸ö<book>½Úµã
xe1.SetAttribute("genre","ÀîÔÞºì");//ÉèÖøýڵãgenreÊôÐÔ
xe1.SetAttribute("ISBN","2-3631-4");//ÉèÖøýڵãISBNÊôÐÔ
  ......
ÎÄÕÂÀ´Ô´£ºIT¹¤³Ì¼¼ÊõÍø http://www.systhinker.com/html/43/n-11643.html
ÓõÄÊÇÒ»Öֺܱ¿µÄ·½·¨£¬µ«¿ÉÒÔ°ïÖú³õѧÕßÁ˽â·ÃÎÊXML½ÚµãµÄ¹ý³Ì¡£
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏÂ:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1¡¢Íù<bookstore>½ÚµãÖвåÈëÒ»¸ö<book>½Úµã£º
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//²éÕÒ<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//´´½¨Ò»¸ö<book>½Úµã
xe1.SetAttribute("genre","ÀîÔÞºì");//ÉèÖøýڵãgenreÊôÐÔ
xe1.SetAttribute("ISBN","2-3631-4");//ÉèÖøýڵãISBNÊôÐÔ
  ......
ÓõÄÊÇÒ»Öֺܱ¿µÄ·½·¨£¬µ«¿ÉÒÔ°ïÖú³õѧÕßÁ˽â·ÃÎÊXML½ÚµãµÄ¹ý³Ì¡£
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏÂ:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1¡¢Íù<bookstore>½ÚµãÖвåÈëÒ»¸ö<book>½Úµã£º
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//²éÕÒ<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//´´½¨Ò»¸ö<book>½Úµã
xe1.SetAttribute("genre","ÀîÔÞºì");//ÉèÖøýڵãgenreÊôÐÔ
xe1.SetAttribute("ISBN","2-3631-4");//ÉèÖøýڵãISBNÊôÐÔ
XmlElement xesub1=xmlDoc.CreateElement("title");
......
ÓõÄÊÇÒ»Öֺܱ¿µÄ·½·¨£¬µ«¿ÉÒÔ°ïÖú³õѧÕßÁ˽â·ÃÎÊXML½ÚµãµÄ¹ý³Ì¡£
ÒÑÖªÓÐÒ»¸öXMLÎļþ£¨bookstore.xml£©ÈçÏÂ:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price>
</book>
</bookstore>
1¡¢Íù<bookstore>½ÚµãÖвåÈëÒ»¸ö<book>½Úµã£º
XmlDocument xmlDoc=new XmlDocument();
xmlDoc.Load("bookstore.xml");
XmlNode root=xmlDoc.SelectSingleNode("bookstore");//²éÕÒ<bookstore>
XmlElement xe1=xmlDoc.CreateElement("book");//´´½¨Ò»¸ö<book>½Úµã
xe1.SetAttribute("genre","ÀîÔÞºì");//ÉèÖøýڵãgenreÊôÐÔ
xe1.SetAttribute("ISBN","2-3631-4");//ÉèÖøýڵãISBNÊôÐÔ
XmlElement xesub1=xmlDoc.CreateElement("title");
......
asp.netÖе¼³öExeclµÄ·½·¨£º
ÔÚasp.netÖе¼³öExeclÓÐÁ½ÖÖ·½·¨£¬Ò»ÖÖÊǽ«µ¼³öµÄÎļþ´æ·ÅÔÚ·þÎñÆ÷ij¸öÎļþ¼ÐÏÂÃ棬Ȼºó½«ÎļþµØÖ·Êä³öÔÚä¯ÀÀÆ÷ÉÏ£»Ò»ÖÖÊǽ«ÎļþÖ±½Ó½«ÎļþÊä³öÁ÷д¸øä¯ÀÀÆ÷¡£ÔÚResponseÊä³öʱ£¬t·Ö¸ôµÄÊý¾Ý£¬µ¼³öexeclʱ£¬µÈ¼ÛÓÚ·ÖÁУ¬nµÈ¼ÛÓÚ»»ÐС£
1¡¢½«Õû¸öhtmlÈ«²¿Êä³öexecl
´Ë·¨½«htmlÖÐËùÓеÄÄÚÈÝ£¬Èç°´Å¥£¬±í¸ñ£¬Í¼Æ¬µÈÈ«²¿Êä³öµ½ExeclÖС£
Response.Clear();
Response.Buffer= true;
Response.AppendHeader("Content-Disposition","attachment;filename="+DateTime.Now.ToString("yyyyMMdd")+".xls");
Response.ContentEncoding=System.Text.Encoding.UTF8;
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
ÕâÀïÎÒÃÇÀûÓÃÁËContentTypeÊôÐÔ£¬ËüĬÈϵÄÊôÐÔΪtext/ ......
asp.netÖе¼³öExeclµÄ·½·¨£º
ÔÚasp.netÖе¼³öExeclÓÐÁ½ÖÖ·½·¨£¬Ò»ÖÖÊǽ«µ¼³öµÄÎļþ´æ·ÅÔÚ·þÎñÆ÷ij¸öÎļþ¼ÐÏÂÃ棬Ȼºó½«ÎļþµØÖ·Êä³öÔÚä¯ÀÀÆ÷ÉÏ£»Ò»ÖÖÊǽ«ÎļþÖ±½Ó½«ÎļþÊä³öÁ÷д¸øä¯ÀÀÆ÷¡£ÔÚResponseÊä³öʱ£¬t·Ö¸ôµÄÊý¾Ý£¬µ¼³öexeclʱ£¬µÈ¼ÛÓÚ·ÖÁУ¬nµÈ¼ÛÓÚ»»ÐС£
1¡¢½«Õû¸öhtmlÈ«²¿Êä³öexecl
´Ë·¨½«htmlÖÐËùÓеÄÄÚÈÝ£¬Èç°´Å¥£¬±í¸ñ£¬Í¼Æ¬µÈÈ«²¿Êä³öµ½ExeclÖС£
Response.Clear();
Response.Buffer= true;
Response.AppendHeader("Content-Disposition","attachment;filename="+DateTime.Now.ToString("yyyyMMdd")+".xls");
Response.ContentEncoding=System.Text.Encoding.UTF8;
Response.ContentType = "application/vnd.ms-excel";
this.EnableViewState = false;
ÕâÀïÎÒÃÇÀûÓÃÁËContentTypeÊôÐÔ£¬ËüĬÈϵÄÊôÐÔΪtext/ ......
½ñÌìÔÚÍøÉÏÕÒÁËÐí¾Ã¹ØÓÚsqlserverÖд洢imageÀàÐͺͶÁÈ¡imageµÄ·½·¨£¬¿ÉÊǶ¼ÊÇÄÇôһµã£¬¹ÊÔÚ´ËÂÞÁÐһϣ¬Ï£Íû¿ÉÒÔ°ïÖú´ó¼Ò¡£
Ê×ÏÈÊǹØÓÚdataGridViewµÄ°ó¶¨¡£´úÂë¼ûÏÂ
private void button_show_Click(object sender, EventArgs e)
{
string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
string sqlstr="select * from tast";
SqlConnection conn=new SqlConnection (sqlText);
conn.Open();
SqlCommand comm = new SqlCommand(sqlstr, conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}
ÏÂÃæÊDzåÈëͼÏñµ½Êý¾Ý¿â£¬´úÂëÈçÏ£º
private void button_connect_Click(object sender, EventArgs e)
{
string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
......
½ñÌìÔÚÍøÉÏÕÒÁËÐí¾Ã¹ØÓÚsqlserverÖд洢imageÀàÐͺͶÁÈ¡imageµÄ·½·¨£¬¿ÉÊǶ¼ÊÇÄÇôһµã£¬¹ÊÔÚ´ËÂÞÁÐһϣ¬Ï£Íû¿ÉÒÔ°ïÖú´ó¼Ò¡£
Ê×ÏÈÊǹØÓÚdataGridViewµÄ°ó¶¨¡£´úÂë¼ûÏÂ
private void button_show_Click(object sender, EventArgs e)
{
string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
string sqlstr="select * from tast";
SqlConnection conn=new SqlConnection (sqlText);
conn.Open();
SqlCommand comm = new SqlCommand(sqlstr, conn);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = comm;
da.Fill(ds);
dataGridView1.DataSource = ds.Tables[0];
conn.Close();
}
ÏÂÃæÊDzåÈëͼÏñµ½Êý¾Ý¿â£¬´úÂëÈçÏ£º
private void button_connect_Click(object sender, EventArgs e)
{
string sqlText = "server=localhost;initial catalog=Test; integrated security=true";
......
ÎÊÌâÃèÊö£º
C#³ÌÐò,ÀïÃæcopyÁËÐí¶àÔÀ´µÄ´úÂë,ËùÒԲβÆëµÄ,ºÜÄѶÁ,ÈçºÎ²ÅÄÜÈôúÂë×Ô¶¯ÅÅÆë,¾ÍÏóVS 6.0ÖпÉÒÔʹÓÿì½Ý¼ü,·Ç³£·½±ã.
½â´ð£º
ctrl+a,ÏÈÈ«Ñ¡
ctrl+k,ctrl+f,×Ô¶¯ÅÅÁÐ
»òÕß
ctrl+a,ÏÈÈ«Ñ¡
alt+F8 ×Ô¶¯ÅÅÁÐ ......
ÎÊÌâÃèÊö£º
C#³ÌÐò,ÀïÃæcopyÁËÐí¶àÔÀ´µÄ´úÂë,ËùÒԲβÆëµÄ,ºÜÄѶÁ,ÈçºÎ²ÅÄÜÈôúÂë×Ô¶¯ÅÅÆë,¾ÍÏóVS 6.0ÖпÉÒÔʹÓÿì½Ý¼ü,·Ç³£·½±ã.
½â´ð£º
ctrl+a,ÏÈÈ«Ñ¡
ctrl+k,ctrl+f,×Ô¶¯ÅÅÁÐ
»òÕß
ctrl+a,ÏÈÈ«Ñ¡
alt+F8 ×Ô¶¯ÅÅÁÐ ......
ÎÊÌâÃèÊö£º
C#³ÌÐò,ÀïÃæcopyÁËÐí¶àÔÀ´µÄ´úÂë,ËùÒԲβÆëµÄ,ºÜÄѶÁ,ÈçºÎ²ÅÄÜÈôúÂë×Ô¶¯ÅÅÆë,¾ÍÏóVS 6.0ÖпÉÒÔʹÓÿì½Ý¼ü,·Ç³£·½±ã.
½â´ð£º
ctrl+a,ÏÈÈ«Ñ¡
ctrl+k,ctrl+f,×Ô¶¯ÅÅÁÐ
»òÕß
ctrl+a,ÏÈÈ«Ñ¡
alt+F8 ×Ô¶¯ÅÅÁÐ ......