Some basic knowledge after Dan pain (1)

Source: Internet
Author: User

The following are some basic knowledge suitable for beginners. If you are bored, please refer to the previous article.Article..................

Accept direct transfer and pop-up window
Response. Write ("<script language = JavaScript> alert ('method to call response ') </SCRIPT> ");
If (! Ispostback)
{
String id = request. querystring ["ID"]. tostring ();

upload an image:
string fullname = This. fileupload1.filename;
string filename = fullname. substring (fullname. lastindexof ("//") + 1);
string type = fullname. substring (fullname. lastindexof (". ") + 1);
If (type =" jpg "| type =" BMP "| type =" GIF ")
{< br> This. fileupload1.postedfile. saveas (server. mappath ("up") + "//" + filename);
This. IMG. imageurl = "up" + "/" + filename; // Image Display
}< br> else
response. write ("");

Check whether the user name exists:
Method 1:

Sqlconnection con = new sqlconnection ("Server =.; database = text; uid = sa; Pwd = ;");
Con. open ();
Sqlcommand COM = new sqlcommand ("select count (*) from [use] Where uername = '" + username. text + "'and Pwd ='" + userpwd. text + "'", con );
Int COUNT = convert. toint32 (COM. executescalar ());
If (count> 0)
{
Label1.text = "the user name already exists ";

}
Else
{
Label1.text = "the user name does not exist ";
}

2nd methods:

Methods In the class:
Public int gvdababind (string strcon)
{
Int;
Sqlconnection con = new sqlconnection (configurationmanager. etettings ["connectionstring"]);
Con. open ();
Sqlcommand COM = new sqlcommand (strcon, con );
A = convert. toint32 (COM. executescalar ());
Con. Close ();
Return;

}

In the backgroundCode:
Int A = dbnew. gvdababind ("select count (*) from [use] Where uername = '" + username. text + "'and Pwd ='" + userpwd. text + "'");
If (a> 0)
{
Label1.text = "the user name already exists ";

}
Else
{
Label1.text = "the user name does not exist ";
}

Provincial/Municipal linkage:

Methods In the class:
Public void ddlbind (dropdownlist DDL, string STR, string name, string ID)
{
Sqlconnection con = new sqlconnection (configurationmanager. etettings ["connectionstring"]);
Con. open ();
Sqldataadapter da = new sqldataadapter (STR, con );
Dataset DS = new dataset ();
Da. Fill (DS );
DDL. datasource = Ds;
DDL. datatextfield = Name;
DDL. datavaluefield = ID;
DDL. databind ();
Con. Close ();
// Return ID;

}

Foreground call method:
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
DB. ddlbind (ddlpro, "select * From Provice", "proname", "proid ");
}
Protected void ddlpro_selectedindexchanged (Object sender, eventargs E)
{
DB. ddlbind (ddlcity, "select * from city where proid =" + ddlpro. selectedvalue + "", "cityname", "cityid ");
}
{

Read XML file information:

Filestream FS = new filestream (server. mappath ("xmlfile. xml"), filemode. Open, fileaccess. Read );
Streamreader sr = new streamreader (FS );
Dataset ds1 = new dataset ();
Ds1.readxml (SR );
Gvxml. datasource = ds1.tables [0];
Gvxml. databind ();

Use the dataset returned method to read the table content in dataset.

method: Public dataset returnds ()
{< br> sqlconnection con = new sqlconnection (datacon ();
con. open ();
sqldataadapter da = new sqldataadapter ("select * from [use]", con);
dataset DS = new dataset ();
da. fill (DS);
return Ds;
con. close ();

}
Call:
Dataset DS = new dataset ();
DS = dB. returnds ();
Datarowview DRV = Ds. Tables [0]. defaultview [0];
Lbname. Text = convert. tostring (DRV. Row ["uername"]);
Lbpwd. Text = convert. tostring (DRV. Row ["PWD"]);
Datarowview drv1 = Ds. Tables [0]. defaultview [1];
Lbname2.text = convert. tostring (drv1.row ["uername"]);
Lbpwd2.text = convert. tostring (drv1.row ["PWD"]);

Simple Digital verification code:

Random RD = new random ();
Lbnumber. Text = RD. Next (1000,100 00). tostring ();
Digit/letter combination verification code

Public void generatecheckcode ()
{
Int number;
Char code;
String checkcode = string. empty;
Random RD = new random ();
For (INT I = 0; I <4; I ++)
{
Number = RD. Next ();
If (Number % 2 = 0)
Code = (char) ('0' + (char) (Number % 10 ));
Else
Code = (char) ('A' + (char) (Number % 26 ));
Checkcode + = code. tostring ();
}
Label1. Text = checkcode;
}

Template programming for repeater:

<Itemtemplate>
<% # Databinder. eval (container. dataitem, "uername") %>
</Itemtemplate>
<Alternatingitemtemplate>
<% # Databinder. eval (container. dataitem, "uername") %>
</Alternatingitemtemplate>
<Footertemplate> footer </footertemplate>
<Headertemplate> header <Separatortemplate> </separatortemplate>

Set it as the homepage and add the code of this site to Favorites (note that you can only set it in HTML with common Chinese characters instead of using super connections)

<A href = "#" onclick = "this. style. behavior = 'url (# default # homepage) '; this. setHomePage ('HTTP: // www.sina.com ') "> <font color =" #00cc99 "> set as homepage </font> </a>
<A href = "#" onclick = "window. external. addFavorite ('HTTP: // www.sina.com ', 'College students' BBS'); "> <font color =" #00cc99 "> Add your site to favorites </font> </a> & nbsp;

Widget ::

Protected void dldgdd_itemcommand (Object source, datalistcommandeventargs E)
{
String content = (linkbutton) E. Item. findcontrol ("linkbutton1"). text;
Session ["content"] = content;
Response. Redirect ("Main. aspx? Id = "+ content + "");
}

Datalist page:

Public void dlbind ()
{
String id = request. querystring ["ID"]. tostring ();
Int curpage = convert. toint32 (this. label12.text );
Pageddatasource PS = new pageddatasource ();
Dataset DS = NULL;
DS = dB. returndataset ("select * From tb_return where r_fatherid = '" + ID + "'order by r_time DESC", "tb_motif ");
PS. datasource = Ds. Tables ["tb_motif"]. defaultview;
PS. allowpaging = true;
PS. pagesize = 10;
PS. currentpageindex = curpage-1;
This. lkbtnnoback. Enabled = true;
This. lkbtnback. Enabled = true;
This. lkbtnn. Enabled = true;
This. lkbtn1.enabled = true;
If (curpage = 1)
{
This. lkbtn1.enabled = false;
This. lkbtnnoback. Enabled = false;
}
If (curpage = ps. pagecount)
{
This. lkbtnback. Enabled = false;
This. lkbtnn. Enabled = false;
}
Label15.text = convert. tostring (PS. pagecount );
This. dlreturn. datasource = Ps;
This. dlreturn. datakeyfield = "r_id ";
This. dlreturn. databind ();

}

Protected void lkbtn1_click (Object sender, eventargs E)
{
This. label12.text = "1 ";
This. dlbind ();
}

protected void lkbtnnoback_click (Object sender, eventargs e)
{< br> This. label12.text = convert. tostring (convert. toint32 (this. label12.text)-1);
This. dlbind ();
}< br> protected void lkbtnback_click (Object sender, eventargs e)
{< br> This. label12.text = convert. tostring (convert. toint32 (this. label12.text) + 1);
This. dlbind ();
}< br> protected void lkbtnn_click (Object sender, eventargs e)
{< br> This. label12.text = This. label15.text;
This. dlbind ();
}

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.