ASP.NET中常用的三十三種代碼第7/7頁
更新時(shí)間:2007年03月25日 00:00:00 作者:
29.DataGrid使用:
添加刪除確認(rèn):
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
foreach(DataGridItem di in this.DataGrid1.Items)
{
if(di.ItemType==ListItemType.Itemdi.ItemType==ListItemType.AlternatingItem)
{
((LinkButton)di.Cells[8].Controls[0]).Attributes.Add("onclick","return confirm('確認(rèn)刪除此項(xiàng)嗎?');");
}
}
}
樣式交替:
ListItemType itemType = e.Item.ItemType;
if (itemType == ListItemType.Item )
{
e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#FFFFFF';";
e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" ;
}
else if( itemType == ListItemType.AlternatingItem)
{
e.Item.Attributes["onmouseout"] = "javascript:this.style.backgroundColor='#a0d7c4';";
e.Item.Attributes["onmouseover"] = "javascript:this.style.backgroundColor='#d9ece1';cursor='hand';" ;
}
添加一個(gè)編號(hào)列:
DataTable dt= c.ExecuteRtnTableForAccess(sqltxt); //執(zhí)行sql返回的DataTable
DataColumn dc=dt.Columns.Add("number",System.Type.GetType("System.String"));
for(int i=0;i<dt.Rows.Count;i++)
{
dt.Rows[i]["number"]=(i+1).ToString();
}
DataGrid1.DataSource=dt;
DataGrid1.DataBind();
DataGrid1中添加一個(gè)CheckBox,頁面中添加一個(gè)全選框
private void CheckBox2_CheckedChanged(object sender, System.EventArgs e)
{
foreach(DataGridItem thisitem in DataGrid1.Items)
{
((CheckBox)thisitem.Cells[0].Controls[1]).Checked=CheckBox2.Checked;
}
}
將當(dāng)前頁面中DataGrid1顯示的數(shù)據(jù)全部刪除
foreach(DataGridItem thisitem in DataGrid1.Items)
{
if(((CheckBox)thisitem.Cells[0].Controls[1]).Checked)
{
string strloginid= DataGrid1.DataKeys[thisitem.ItemIndex].ToString();
Del (strloginid); //刪除函數(shù)
}
}
30.當(dāng)文件在不同目錄下,需要獲取數(shù)據(jù)庫連接字符串(如果連接字符串放在Web.config,然后在Global.asax中初始化)
在Application_Start中添加以下代碼:
Application["ConnStr"]=this.Context.Request.PhysicalApplicationPath+ConfigurationSettings.
AppSettings["ConnStr"].ToString();
31. 變量.ToString()
字符型轉(zhuǎn)換 轉(zhuǎn)為字符串
12345.ToString("n"); //生成 12,345.00
12345.ToString("C"); //生成 ¥12,345.00
12345.ToString("e"); //生成 1.234500e+004
12345.ToString("f4"); //生成 12345.0000
12345.ToString("x"); //生成 3039 (16進(jìn)制)
12345.ToString("p"); //生成 1,234,500.00%
32、變量.Substring(參數(shù)1,參數(shù)2);
截取字串的一部分,參數(shù)1為左起始位數(shù),參數(shù)2為截取幾位。 如:string s1 = str.Substring(0,2);
33.在自己的網(wǎng)站上登陸其他網(wǎng)站:(如果你的頁面是通過嵌套方式的話,因?yàn)橐粋€(gè)頁面只能有一個(gè)FORM,這時(shí)可以導(dǎo)向另外一個(gè)頁面再提交登陸信息)
<SCRIPT language="javascript">
<!--
function gook(pws)
{
frm.submit();
}
//-->
</SCRIPT> <body leftMargin="0" topMargin="0" onload="javascript:gook()" marginwidth="0" marginheight="0">
<form name="frm" action=" http://220.194.55.68:6080/login.php?retid=7259 " method="post">
<tr>
<td>
<input id="f_user" type="hidden" size="1" name="f_user" runat="server">
<input id="f_domain" type="hidden" size="1" name="f_domain" runat="server">
<input class="box" id="f_pass" type="hidden" size="1" name="pwshow" runat="server">
<INPUT id="lng" type="hidden" maxLength="20" size="1" value="5" name="lng">
<INPUT id="tem" type="hidden" size="1" value="2" name="tem">
</td>
</tr>
</form>
文本框的名稱必須是你要登陸的網(wǎng)頁上的名稱,如果源碼不行可以用vsniffer 看看。
下面是獲取用戶輸入的登陸信息的代碼:
string name;
name=Request.QueryString["EmailName"];
try
{
int a=name.IndexOf("@",0,name.Length);
f_user.Value=name.Substring(0,a);
f_domain.Value=name.Substring(a+1,name.Length-(a+1));
f_pass.Value=Request.QueryString["Psw"];
}
catch
{
Script.Alert("錯(cuò)誤的郵箱!");
Server.Transfer("index.aspx");
}
相關(guān)文章
asp.net 根據(jù)漢字的拼音首字母搜索數(shù)據(jù)庫(附 LINQ 調(diào)用方法)
我們經(jīng)常需要使用拼音首字母來檢索數(shù)據(jù)庫,特別是應(yīng)用于醫(yī)院、商店等行業(yè)軟件中。譬如搜索“zgr”就可以搜索所有包含“中國人”的記錄。那么如果來實(shí)現(xiàn)才能即高效又方便呢?2010-04-04
在Asp.net core項(xiàng)目中使用WebSocket
這篇文章介紹了在Asp.net core項(xiàng)目中使用WebSocket的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08
使用母版頁時(shí)內(nèi)容頁如何使用css和javascript
由于網(wǎng)站的主要頻道頁和列表頁的頭部和底部都是一樣的,如果將每個(gè)頁面放在單獨(dú)的頁面中,當(dāng)頭部和底部需要更改時(shí)維護(hù)量太大。于是想把頭部和底部做成母版頁,頻道頁和列表頁的具體內(nèi)容放到內(nèi)容頁中。這樣當(dāng)頭和底需要改動(dòng)時(shí),只要修改一下母版頁就可以了。2009-08-08
ASP.NET Core使用AutoMapper實(shí)現(xiàn)實(shí)體映射
本文詳細(xì)講解了ASP.NET Core使用AutoMapper實(shí)現(xiàn)實(shí)體映射的方法,文中通過示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-03-03
.net c# gif動(dòng)畫如何添加圖片水印實(shí)現(xiàn)思路及代碼
本文將詳細(xì)介紹下c#實(shí)現(xiàn)gif動(dòng)畫添加圖片水印,思路很清晰,感興趣的你可以參考下哈,希望可以幫助到你2013-03-03

