欢迎光临
我们一直在努力

ASP.NET简单整理收藏(1)-.NET教程,Asp.Net开发

建站超值云服务器,限时71元/月

 

//连接数据库:
<appsettings>
<add key=”sqllink” value=”server=yfq-001;uid=adm;pwd=sdadm;database=dbmt50″></add>
</appsettings>
//登录
string connstr=system.configuration.configurationsettings.appsettings[“sqllink”];
sqlconnection conn=new sqlconnection(connstr);
conn.open();
string sql=”select count(*) as icount from sysoper where logname=”+this.usrname.text+””;
sqlcommand comm=new sqlcommand(sql,conn);
sqldatareader dr1=comm.executereader();
dr1.read();
string count=dr1[“icount”].tostring();
dr1.close();
if(count!=”0″)
{
 sql=”select * from sys where logname=”+this.usrname.text+””;
 sqlcommand  comm1=new sqlcommand(sql,conn);
 sqldatareader dr=comm1.executereader();
 dr.read();
 string drpwd=dr[“logpass”].tostring();
 dr.close();
 if(drpwd==this.usrpwd.text)
 {
  this.session[“logid”]=this.usrname.text.trim();
  if(dr[“plcname”].tostring()==””)
  {
   this.session[“level”]=”1″;
  }
  if(dr[“plcname”].tostring()!=””)
  {
   this.session[“level”]=”2″;
   this.session[“plcname”]=dr[“plcname”].tostring();
  } 
  this.response.redirect(“main.aspx”);
 }
 else
 {
  this.response.write(“<script>alert(登录密码错误!)</script>”);
 }
}
if(count==”0″)
{
 this.response.write(“<script>alert(没有这个用户!)</script>”);
}
//框架的使用
<html>
<head>
<title>xxxxx</title>
<meta http-equiv=”content-type” content=”text/html; charset=gb2312″>
</head>
<frameset rows=”60,*” cols=”*” border=”0″ framespacing=”0″ frameborder=”0″>
 <frame name=”topframe” src=”top.aspx” scrolling=”no” noresize>
 <frameset style=”cursor: w-resize” border=”0″ framespacing=”12″ frameborder=”yes” cols=”143,74%”>
  <frame name=”leftframe” bordercolor=”#99ccff” src=”left.aspx”>
  <frame name=”mainframe” src=”bottom.htm”>
 </frameset>
</frameset>
</html>
//treeview的使用
<iewc:treenode navigateurl=”aa/bb.aspx” text=”设置” target=”mainframe”></iewc:treenode>
//datagrid的应用
//动态添加列
boundcolumn column1=new boundcolumn();
column1.headertext=”用户”;       
column1.datafield=”usrname”;   
column1.headerstyle.wrap=false;      
column1.itemstyle.wrap=false;   
column1.itemstyle.horizontalalign=horizontalalign.center;
column1.headerstyle.horizontalalign=horizontalalign.center;
this.datagrid1.columns.add(column1);

hyperlinkcolumn linkcolumn=new hyperlinkcolumn();
linkcolumn.headertext=”帐号”;
linkcolumn.datanavigateurlfield=”actid”;
linkcolumn.datatextfield=”actid”;
//linkcolumn.datanavigateurlformatstring=”bak.aspx?actid={0}”; 
   

linkcolumn.datanavigateurlformatstring=”javascript:varwin=window.open(bak.aspx?id={0});window.close()”;
linkcolumn.headerstyle.wrap=false;
linkcolumn.itemstyle.wrap=false;
linkcolumn.itemstyle.horizontalalign=horizontalalign.center;
linkcolumn.headerstyle.horizontalalign=horizontalalign.center;
this.datagrid1.columns.add(linkcolumn); 

hyperlinkcolumn linkcolumn1=new hyperlinkcolumn();
linkcolumn1.datanavigateurlfield=”actid”;
linkcolumn1.headertext=”修改”;
linkcolumn1.text=”修改”;
linkcolumn1.datanavigateurlformatstring=”edit_usr.aspx?actid={0}”;
linkcolumn1.headerstyle.wrap=false;
linkcolumn1.itemstyle.wrap=false;
linkcolumn1.visible=true;
linkcolumn1.headerstyle.horizontalalign=horizontalalign.center;
linkcolumn1.itemstyle.horizontalalign=horizontalalign.center;
this.datagrid1.columns.add(linkcolumn1);

hyperlinkcolumn linkcolumn2=new hyperlinkcolumn();
linkcolumn2.datanavigateurlfield=”actid”;
linkcolumn2.headertext=”删除”;
linkcolumn2.text=”删除”;
linkcolumn2.datanavigateurlformatstring=”del.aspx?actid={0}”;
linkcolumn2.headerstyle.wrap=false;
linkcolumn2.itemstyle.wrap=false;
linkcolumn2.visible=true;
linkcolumn2.headerstyle.horizontalalign=horizontalalign.center;
linkcolumn2.itemstyle.horizontalalign=horizontalalign.center;
this.datagrid1.columns.add(linkcolumn2);

string connstr=system.configuration.configurationsettings.appsettings[“sqllink”];
sqlconnection conn=new sqlconnection(connstr);
conn.open();
string sql=”select * from usract”;
sqldataadapter dr=new sqldataadapter(sql,conn);
dataset ds=new dataset();
dr.fill(ds,”usract”);
this.datagrid1.datasource=ds.tables[“usr”].defaultview;
this.datagrid1.databind();
this.record.text=”共” + ds.tables[“usr”].rows.count.tostring() + “条”;
this.pagenow.text=”第” +(this.datagrid1.currentpageindex + 1).tostring() +”/”;
this.pagetotal.text=this.datagrid1.pagecount.tostring ()+”页”;
this.dropdownlist1.items.clear();
for(int i=1;i<=this.datagrid1.pagecount;i++)

 this.dropdownlist1.items.add(i.tostring());
}
this.dropdownlist1.items[(this.datagrid1.currentpageindex)].selected=true;
this.dropdownlist1.selecteditem.text =(this.datagrid1 .currentpageindex+1).tostring();
//默认分页
public void navigatetopage(object sender, system.eventargs e)
{
 string pageinfo  = ((linkbutton)sender).commandname;
 switch (pageinfo)
 {
  case “第一页”:
  datagrid1.currentpageindex = 0;
  break;
  case “上一页”:
  if (datagrid1.currentpageindex > 0)
  datagrid1.currentpageindex -= 1;
  break;
  case “下一页”:
  if (datagrid1.currentpageindex < (datagrid1.pagecount – 1))
  datagrid1.currentpageindex += 1;
  break;
  case “最后一页”:
  datagrid1.currentpageindex = (datagrid1.pagecount – 1);
  break;
 }
 this.linkdb();

//跳页
this.datagrid1.currentpageindex=convert.toint32(this.dropdownlist1.selecteditem.text)-1;
this.linkdb();
//分页条
<table id=”table2″ cellspacing=”0″ cellpadding=”0″ width=”512″ align=”left” border=”0″ runat=”server” style=”width: 512px;

height: 22px”>
<tr>
<td nowrap>
<p align=”center”>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:label id=”label1″ runat=”server” forecolor=”white”>每页显示20条记录</asp:label></p>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:label id=”record” runat=”server” forecolor=”white”>label</asp:label>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:label id=”pagenow” runat=”server” forecolor=”white”>label</asp:label>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:label id=”pagetotal” runat=”server” forecolor=”white”>label</asp:label>
</td>
<td nowrap width=”5″></td>
<td nowrap>
asp:linkbutton id=”btnfirstpage” onclick=”navigatetopage” runat=”server” forecolor=”white” commandname=”第一页”>首页

</asp:linkbutton>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:linkbutton id=”btnpreviouspage” onclick=”navigatetopage” runat=”server” forecolor=”white” commandname=”上一页”>上一页

</asp:linkbutton>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:linkbutton id=”btnnextpage” onclick=”navigatetopage” runat=”server” forecolor=”white” commandname=”下一页”>下一页

</asp:linkbutton>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:linkbutton id=”btnlastpage” onclick=”navigatetopage” runat=”server” forecolor=”white” commandname=”最后一页”>末页

</asp:linkbutton>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:label id=”label2″ runat=”server” forecolor=”white” width=”54px”>跳转到</asp:label>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:dropdownlist id=”dropdownlist1″ runat=”server” width=”48px” autopostback=”true”></asp:dropdownlist>
</td>
<td nowrap width=”5″></td>
<td nowrap>
<asp:label id=”label3″ runat=”server” forecolor=”white” width=”15px”>页</asp:label>
</td>
<td nowrap width=”5″></td>
<td nowrap>
</td>
</tr>
</table>
//传参
private void datagrid1_itemdatabound_4(object sender, system.web.ui.webcontrols.datagriditemeventargs e)
{
 //特效
 if(e.item.itemindex!=-1)
 {
  int orderid=e.item.itemindex+1;
  e.item.cells[0].text=orderid.tostring();    

e.item.attributes.add(“onmouseover”,”this.setattribute(bkc,this.style.backgroundcolor);this.style.backgroundcolor=#3a6ea5

“);
  e.item.attributes .add(“onmouseout”,”this.style.backgroundcolor=this.getattribute(bkc);”);
  if(e.item.itemtype==listitemtype.alternatingitem||e.item.itemtype==listitemtype.item)
  {
  //弹出一个完整的ie窗口   

e.item.attributes.add(“onclick”,”window.open(message.aspx?actid=”+e.item.cells[1].text+”);”);    

//e.item.attributes.add(“onclick”,”window.open(detail.aspx?id=”+e.item.cells[1].text+”,newwin,width=750,height=600,scrol

lbars=yes,top=50,left=50);”);
  }
 }
}
response.write(“<script>window.open(excel.aspx,_blank);</” + “script>”);
this.linkdb();
//
string sql=”select * from view_usract where actid=”+session[“strmta”].tostring()+””;
sqlcommand cmd=new sqlcommand(sql,conn);
try
{
 sqldatareader dr=cmd.executereader();
 if(dr.read())
 {  
  this.actidtext.text=dr[0].tostring();
  this.usrnametext.text=dr[1].tostring();
 }
}
//添加
sql=”insert into contlist()

values(“+this.txtactid.text.trim()+”,”+count.tostring()+”,”+this.txtcname.text.trim()+”,”+this.txtcrank.text.trim()+”

,”+this.txtcphone1.text.trim()+”,”+this.txtcphone2.text.trim()+”,”+this.txthdphone.text.trim()+”,”+this.txthmphone.tex

t.trim()+”,”+this.txtcontbp.text.trim()+”,”+this.txtcmemo.text.trim()+”,”+sqlstr+”)”;
sqlcommand  mycommand=new sqlcommand(sql,conn);
mycommand.executenonquery();
//修改
string sql1=””;
sql1=”update contlist set routeid=”+sqlstr+” where actid=”+this.txtactid.text.trim()+””;
sqlcommand  cmd=new sqlcommand(sql1,conn);
cmd.executenonquery();
//调用存储过程
sqlcommand cmd1=new sqlcommand(“pro_planalme”,conn);
cmd1.commandtype = commandtype.storedprocedure; 
cmd1.parameters.add(“@aa”,this.txtactid.text.trim());
cmd1.executenonquery();
//
if(this.page.isvalid)
{
 try
 {
  this.response.write(“<script>alert(添加成功);</script>”);
 }
 catch(exception e)
 {
  this.response.write(e.tostring());
  this.response.write(“<script>alert(添加不成功);</script>”);
 }
 finally
 {
  conn.close();
 }
}
else
{
 this.response.write(“<script>alert(修改不成功);</script>”);
}
 
private void customvalidator1_servervalidate(object source, system.web.ui.webcontrols.servervalidateeventargs args)
{//姓名(txtcname)
 try
 {
  int bytecount=system.text.encoding.default.getbytecount(this.txtcname.text.trim());
  if(bytecount>10)
  {
   args.isvalid=false;
   return;
  }
 }
 catch(exception)
 {
 }
 args.isvalid=true;
}
//修改               

update contlist set cname=@cname where (contid=@contid and actid=@actid)”; 
sqlcommand cmd=new sqlcommand(sql,conn);
cmd.parameters.add(new sqlparameter(“@actid”,sqldbtype.varchar));
cmd.parameters[“@actid”].value=”000004″;
//序号
cmd.parameters.add(new sqlparameter(“@contid”,sqldbtype.varchar));
cmd.parameters[“@contid”].value=this.request.params[“contid”].tostring();
cmd.executenonquery();

//删除
this.response.write(“<script language=javascript>”);
this.response.write(“aa=window.confirm(您确定要删除联系人);”);
this.response.write(“if(aa==false){“);
this.response.write(“window.location.href=contlist.aspx”);
this.response.write(“}”);
this.response.write(“if(aa==true)”);
this.response.write(“{“);
this.response.write(“window.location.href=del_cont.aspx”);
this.response.write(” } “); 
this.response.write(“</script>”);

string sql=””;
sql=”delete from contlist where contid=”+this.session[“contid”].tostring()+” and actid=000004″;
sqlcommand  cmd=new sqlcommand(sql,conn);
sqlcommand cmd1=new sqlcommand(“pro_planalmevt_intoplanalmevtget”,conn);
cmd1.commandtype = commandtype.storedprocedure; 
cmd1.parameters.add(“@actid”,”000004″); 
cmd.executenonquery();
cmd1.executenonquery();
this.response.write(“<script>alert(删除成功)</script>”);       

this.response.write(“<script>window.location.href=contlist.aspx</script>”);

//打印

<style>
 body { scrollbar-base-color: #99ccff }
</style>
<style media=”print”>
.noprint { display: none }
unknown { page-break-after: always }
</style>
<style>
.style_td { border-right: #ffffff 0px solid; border-top: #ffffff 0px solid; border-left: #000000 1px solid; border-bottom:

#000000 1px solid }
.style_tab { border-right: #000000 2px solid; border-top: #000000 2px solid; border-left: #000000 1px solid; border-bottom:

#000000 1px solid }
.noprint { font-size: 9pt; font-family: “宋体” }
</style>

<td align=”center”><!–#include file=”print.html” –><font face=”宋体”></font></td>

<center class=”noprint”>
<p>
<object id=”webbrowser” classid=”clsid:8856f961-340a-11d0-a96b-00c04fd705a2″ height=”0″ width=”0″ viewastext>
</object>
<input type=”button” value=”打印” onclick=”document.all.webbrowser.execwb(6,1)”> <input type=”button” value=”直接打印”

onclick=”document.all.webbrowser.execwb(6,6)”>
<input type=”button” value=”页面设置” onclick=”document.all.webbrowser.execwb(8,1)”>
<input type=”button” value=”打印预览” onclick=”document.all.webbrowser.execwb(7,1)”>
</p>
</center>
//取得ip地址
string hostip=system.net.dns.gethostbyname(system.net.dns.gethostname()).addresslist[0].tostring();

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » ASP.NET简单整理收藏(1)-.NET教程,Asp.Net开发
分享到: 更多 (0)

相关推荐

  • 暂无文章