Asp. NET Simple collation Collection (1)

Source: Internet
Author: User
asp.net

To connect to a database:
<appSettings>
<add key= "Sqllink" value= "Server=yfq-001;uid=adm;pwd=sdadm;database=dbmt50" ></add>
</appSettings>
Login
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 (' Login password Error! ') </script> ");
}
}
if (count== "0")
{
This. Response.Write ("<script>alert" (' no this user!) ') </script> ");
}
Use of the framework
<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= "frameborder=" "Yes" cols= "143,74%" >
<frame name= "Leftframe" bordercolor= "#99ccff" src= "left.aspx" >
<frame name= "MainFrame" src= "bottom.htm" >
</frameset>
</frameset>
</HTML>
Use of the TreeView
<iewc:treenode navigateurl= "aa/bb.aspx" text= "Settings" target= "MainFrame" ></iewc:TreeNode>
The application of the DataGrid
Add columns Dynamically
BoundColumn column1=new BoundColumn ();
Column1. headertext= "User";
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= "account Number";
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= "modification";
Linkcolumn1. text= "modification";
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= "Delete";
Linkcolumn2. text= "Delete";
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= "Total" + ds. tables["usr"]. Rows.Count.ToString () + "strip";
This.pagenow.text= "The first" + (this. Datagrid1.currentpageindex + 1). ToString () + "/";
This.pagetotal.text=this. DataGrid1.PageCount.ToString () + "page";
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 ();
Default paging
public void Navigatetopage (object sender, System.EventArgs e)
{
String PageInfo = ((LinkButton) sender). CommandName;
Switch (PageInfo)
{
Case "First page":
Datagrid1.currentpageindex = 0;
Break
Case "Previous page":
if (Datagrid1.currentpageindex > 0)
Datagrid1.currentpageindex-= 1;
Break
Case "Next page":
if (Datagrid1.currentpageindex < (datagrid1.pagecount-1))
Datagrid1.currentpageindex + 1;
Break
Case "Last page":
Datagrid1.currentpageindex = (datagrid1.pagecount-1);
Break
}
THIS.LINKDB ();
}
Jump page
This. Datagrid1.currentpageindex=convert.toint32 (this. DropDownList1.SelectedItem.Text)-1;
THIS.LINKDB ();
Page-Bar
<table id= "Table2" cellspacing= "0" cellpadding= "0" width= "" align= "left" border= "0" runat= "Server" style= "width: 512px;

height:22px
<tr>
<td nowrap>
<p align= "center" >      &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP
<asp:label id= "Label1" runat= "server" forecolor= "White" > Display 20 records per page </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" runat= "Server" Forecolor= "White" commandname= "first page" > Home

</asp:linkbutton>
</TD>
<TD noWrap width= "5" ></TD>
<TD nowrap>
<asp:linkbutton id= "Btnpreviouspage" runat= "server" forecolor= "White" commandname= "Previous page" > previous page

</asp:linkbutton>
</TD>
<TD noWrap width= "5" ></TD>
<TD nowrap>
<asp:linkbutton id= "Btnnextpage" runat= "server" forecolor= "white" commandname= "Next" > next page

</asp:linkbutton>
</TD>
<TD noWrap width= "5" ></TD>
<TD nowrap>
<asp:linkbutton id= "Btnlastpage" runat= "server" forecolor= "white" commandname= "last Page" > last

</asp:linkbutton>
</TD>
&LT;TD noWrap width= "5" ></TD>
&LT;TD nowrap>
<asp:label id= "Label2" runat= "server" forecolor= "white" width= "54px" > Jump to </asp:label>
</TD>
&LT;TD noWrap width= "5" ></TD>
&LT;TD nowrap>
<asp:dropdownlist id= "DropDownList1" runat= "Server" width= "48px" autopostback= "True" ></asp:dropdownlist >
</TD>
&LT;TD noWrap width= "5" ></TD>
&LT;TD nowrap>
<asp:label id= "Label3" runat= "server" forecolor= "white" width= "15px" > Page </asp:label>
</TD>
&LT;TD noWrap width= "5" ></TD>
&LT;TD nowrap>
</TD>
</TR>
</TABLE>
Pass Reference
private void Datagrid1_itemdatabound_4 (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
Effects
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)
{
Pop up a complete IE window

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 ();
}
}
Add to
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 ();
Modify
String sql1= "";
sql1= "Update contlist set routeid= '" +sqlstr+ "' Where Actid= '" +this.txtactid.text.trim () + "'";
SqlCommand cmd=new SqlCommand (sql1,conn);
Cmd. ExecuteNonQuery ();
Calling stored procedures
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 (' Add success ');</script>");
}
catch (Exception E)
{
This. Response.Write (E.tostring ());
This. Response.Write ("<script>alert (' Add unsuccessful ');</script>");
}
Finally
{
Conn. Close ();
}
}
Else
{
This. Response.Write ("<script>alert (' modification unsuccessful ');</script>");
}

private void CustomValidator1_ServerValidate (object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{//Name (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;
}
Modify

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";
Serial number
Cmd. Parameters.Add (New SqlParameter ("@ContID", SqlDbType.VarChar));
Cmd. parameters["@ContID"]. Value=this. request.params["Contid"]. ToString ();
Cmd. ExecuteNonQuery ();

//Delete
this. Response.Write ("<script language= ' JavaScript ' >");
this. Response.Write ("Aa=window.confirm (' You are sure to delete contact ');";
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 (' delete success ') </script>");

This. Response.Write ("<script>window.location.href= ' contlist.aspx ' </script>");

Print

<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: "Song Body"}
</style>

<TD align= "center" ><!--#include file= "print.html"--><font face= "song Body" ></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= "print" > <input type= "button" value= "Direct printing"

>
<input type= "button" value= "Page Setup" >
<input type= "button" value= "Print Preview" >
</p>
</center>
Get IP Address
String Hostip=system.net.dns.gethostbyname (System.Net.Dns.GetHostName ()). Addresslist[0]. ToString ();




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.