servervariables變量集合

<% @ Page Language="C#" %>
<% @ Import Namespace="System.Data" %>
<script language="C#" runat="server">
public void Page_Load(object src,EventArgs e)
{
 //取得servervariables變量集合
 
 NameValueCollection ServerVariables=Request.ServerVariables;
 
 //產生一個數據表
 DataTable dt=new DataTable();
 DataRow dr;

 dt.Columns.Add(new DataColumn("環境變量",typeof(string)));
 dt.Columns.Add(new DataColumn("變量值",typeof(string)));

 foreach(string SingleVariable in ServerVariables)
 {
  dr=dt.NewRow();
  dr[0]=SingleVariable;
  dr[1]=ServerVariables[SingleVariable].ToString();
  dt.Rows.Add(dr);
 }

 DataGrid1.DataSource=new DataView(dt);
 DataGrid1.DataBind();
}
</script>
<html>
<head>
<title>
serverVariables變量值
</title>
</head>
<body>
<asp:DataGrid id="DataGrid1" runat="server"
borderColor="black"
Borderwidth="1"
GridLines="Both"
cellPadding="3"
CellSpacing="0"
Font-Size="8pt"
headerStyle-BackColor="#aaaadd"
AlternatingItemStyle-BackColor="#eeeeee"
/>
</body>
</html>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章