当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET中常用的三十三种代码第1/7页

ASP.NET中常用的三十三种代码第1/7页

2018年04月28日  | 移动技术网IT编程  | 我要评论

比优特公司答疑,邢台吧,瘙痒病


29.datagrid使用:
添加删除确认: 
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('确认删除此项吗?');"); 

 } 

样式交替: 
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';" ; 

添加一个编号列: 
datatable dt= c.executertntableforaccess(sqltxt); //执行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中添加一个checkbox,页面中添加一个全选框 
private void checkbox2_checkedchanged(object sender, system.eventargs e) 

 foreach(datagriditem thisitem in datagrid1.items) 
 { 
((checkbox)thisitem.cells[0].controls[1]).checked=checkbox2.checked; 
 } 

将当前页面中datagrid1显示的数据全部删除 
foreach(datagriditem thisitem in datagrid1.items) 

 if(((checkbox)thisitem.cells[0].controls[1]).checked) 
 { 
string strloginid= datagrid1.datakeys[thisitem.itemindex].tostring(); 
del (strloginid); //删除函数 
 } 

30.当文件在不同目录下,需要获取数据库连接字符串(如果连接字符串放在web.config,然后在global.asax中初始化)
在application_start中添加以下代码: 
application["connstr"]=this.context.request.physicalapplicationpath+configurationsettings. 
 appsettings["connstr"].tostring(); 
31. 变量.tostring() 
字符型转换 转为字符串 
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进制) 
12345.tostring("p"); //生成 1,234,500.00% 
32、变量.substring(参数1,参数2);
截取字串的一部分,参数1为左起始位数,参数2为截取几位。 如:string s1 = str.substring(0,2); 
33.在自己的网站上登陆其他网站:(如果你的页面是通过嵌套方式的话,因为一个页面只能有一个form,这时可以导向另外一个页面再提交登陆信息)
<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> 
文本框的名称必须是你要登陆的网页上的名称,如果源码不行可以用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("错误的邮箱!"); 
 server.transfer("index.aspx"); 

7

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网