Asp.Netǰ̨µ÷Óúǫ́±äÁ¿
1. Asp.NetÖм¸ÖÖÏàËƵıê¼Ç·ûºÅ: < %=...%>< %#... %>< % %>< %@ %>½âÊͼ°Ó÷¨
´ð: < %#... %>: ÊÇÔڰ󶨿ؼþDataBind()·½·¨Ö´ÐÐʱ±»Ö´ÐУ¬ÓÃÓÚÊý¾Ý°ó¶¨
Èç: < %# Container.DataItem("tit") %>
< %= %>: ÔÚ³ÌÐòÖ´ÐÐʱ±»µ÷Ó㬿ÉÒÔÏÔʾºǫ́±äÁ¿Öµ
Èç:
*.aspxÖУº < %= aaa %>
*.csÖÐ: protected string aaa="ÐÕÃû";
< % %>: ÄÚÁª´úÂë¿éÀïÃæ¿ÉÒÔÔÚÒ³ÃæÎļþ*.aspx»ò*.ascxÎļþÀïÃæǶÈëºǫ́´úÂë
Èç:
< %
for(int i=0;i<100;i++)
{
Reaponse.Write(i.ToString());
}
%>
< %@ %>ÊÇÔÚ*.aspxÒ³Ãæǰ̨´úÂëµ¼ÈëÃüÃû¿Õ¼ä,
Èç:
< %@ Import namespace="System.Data"%>
2.¿Ø¼þ½ÓÊÕÄÄЩÀàÐÍÊý¾Ý?
´ð:½ÓÊÕBindµÄ¿Ø¼þ£¬Ò»°ãÓÐDropDownList,DataList,DataGrid,ListBoxÕâЩ¼¯ºÏÐÔÖʵĿؼþ£¬¶ø±»À¦°ó µÄÖ÷ÒªÊÇArrayList(Êý×é),Hashtable(¹þÏ¡±í),DataView(Êý¾ÝÊÓͼ),DataReaderÕâËĸö£¬ÒÔºóÎÒÃǾͿÉÒÔ ¶ÔºÅÈë×ù£¬²»»á³öÏÖDataTable±»À¦°óµÄ´íÎóÁË£º£©
3.DataBind,»ñµÃµÄÊý¾Ý£¬ÏµÍ³»á½«ÆäĬÈÏΪString,ÔõÑùת»¯ÎªÆäËüµÄÀàÐÍ?
DataBinder.Eval(Container.DataItem,"ת»»µÄÀàÐÍ","¸ñʽ")
×îºóÒ»¸ö"¸ñʽ"ÊÇ¿ÉÑ¡µÄ£¬Ò»°ã²»ÓÃÈ¥¹ÜËû£¬Container.DataItemÊÇÀ¦°óµÄÊý¾ÝÏî,"ת»»ÀàÐÍ"Ö¸µÄÊÇ Integer,String,BooleanÕâÒ»ÀණÎ÷.
4.Ö÷ÒªÃüÃû¿Õ¼ä:
< % @ Import Namespace="System.Data" %> ´¦ÀíÊý¾ÝʱÓõ½
< % @ Import Namespace="System.Data.ADO" % > ʹÓÃADO.net ; ʱÓõ½
< % @ Import Namespace="System.Data.SQL" %> SQL Server Êý¾Ý¿âרÓÃ
< % @ Import Namespace="System.Data.XML" %> ²»Óÿ´´¦ÀíXMLÓõ½
< % @ Import Namespace="System.IO" %> ´¦ÀíÎļþʱÓõ½
< % @ Import Namespace="System.Web.Util" %> ·¢Óʼþʱ´ó¼Ò»áÓõ½
< % @ Import Namespace="System.Text" %> Îı¾±àÂëʱÓõ½
5.Connections(SQLConection »òÕß ADOConnection)µÄ³£ÓÃÊôÐԺͷ½·¨:
| ConnectionString È¡µÃ»òÉèÖÃÁ¬½áÊý¾Ý¿âµÄÓï¾ä
| ConnectionTimeout È¡µÃ»òÉèÖÃÁ¬½áÊý¾Ý¿âµÄ×ʱ¼ä£¬Ò²ÊǾͳ¬Ê±Ê±¼ä
| DataBase È¡µÃ»òÉèÖÃÔÚÊý¾Ý¿â·þÎñÆ÷ÉÏÒª´ò¿ªµÄÊý¾Ý¿âÃû
| DataSource È¡µÃ»òÉèÖÃDSN,´ó¼Ò²»»áÄ°Éú°É£º£©
| Password È¡µÃ»òÉèÖÃÃÜÂë
| UserID È¡µÃ»òÉèÖõǽÃû
| State È¡µÃÄ¿Ç°
Ïà¹ØÎĵµ£º
Ê×Ò³£º
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head ......
ÔÚASP.NET 2.0 WEÕ¾µãÉÏ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÔÚweb.configÎļþÖмÓÈëÏÂÃæµÄ½ÚµãÀ´Ö§³ÖÌõ¼þ±àÒë¡£
<compilers>
<compiler language="c#" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"
¡¡¡¡extension ......
public void MyGetDepart()
{
string sSql = @"select DepartId,DepartName as 'Ç廪¸½ÖÐ',ParentId from sDepart";
DataTable table = CommClass.GetDataTable(sSql);//BoolDAL.DbHelper.GetDataTabl ......
1¡¢¿ØÖÆGridView¿Ø¼þÖÐÄÚÈݵĻ»ÐÐ
GridView1.Attributes.Add("style","word-break:keep-all;word-wrap:normal");//Õý³£»»ÐÐ
GridView1.Attributes.Add("style","word-break:break-all;word-wrap:break-word");//×Ô¶¯»»ÐÐ
2¡¢É¾³ýGridView¿Ø¼þÐÐÐÅÏ¢µ¯³öÈ·ÈÏÌáʾ¿ò
ÔÚGridViewµÄRowDataBound()ʼþÖÐÌ ......