您的位置:首页 > 编程语言 > C#

C#相关知识

2015-08-19 22:46 441 查看
1、style

.style1

{

text-align: center;

font-size: xx-large;

color:Blue;

background-color: #A0FFFF;

width: 80%;

margin-left: 10%;

height:650px;

}

2、调用别的模块,比如说登录模块

<uc1:enter ID="enter1" runat="server" />

<div style=" width:100%; height:30px;background-color:#F0F8FF; ">段子</div>

<br /> 空行

3、datalist

<asp:DataList ID="DataList1" runat="server" Width="100%" BorderWidth="0px">

<ItemTemplate> //模板

<div style=" width:20px; text-align:center; height:120px; float:left;" ><p><%# DataBinder.Eval(Container.DataItem, "id")%> </p></div> //数据绑定

<div style="width:110px;height:120px; float:left"

<p align="center">

<asp:Image id="Image1" Width="100" Height="100" runat="server" ImageUrl='<%# "../Default.aspx?ImgID="+ DataBinder.Eval(Container,"DataItem.id")%>'>

</asp:Image>

<%# DataBinder.Eval(Container.DataItem, "id")%>  

</p>

</div>

<div style="width:110px;height:120px; float:left">

<a >

<asp:Image id="Image2" Width="30" Height="30" runat="server" ImageUrl='<%# "../Default.aspx?ImgID="+ DataBinder.Eval(Container,"DataItem.id")%>'>

</asp:Image>

<%# DataBinder.Eval(Container.DataItem, "id")%>

</a>

</div>

</div>

<div style="width:40px;height:120px; float:right">

<div style=" height:40; width:40px;background-color:#F5F5F5"></div>

<div style=" height:40; width:40px;background-color:#F5F5F5"></div>

<div style=" height:40; width:40px;background-color:#F5F5F5"></div>

</div>

</ItemTemplate>

</asp:DataList>

4、连接数据库的类

public class db

{

public static string connstring =

//@"data source=WIN7-20140423SZ\SQLEXPRESS; Initial Catalog=user_login;integrated security=SSPI";

@"server=qds148466258.my3w.com;user id=qds148466258;password=huzhenghui119; Initial Catalog=qds148466258_db";

// @"Data Source=.\SQLEXPRESS;Initial Catalog=WEBSQL;Integrated Security=SSPI";

public static void DoSql(string sql)

{

SqlConnection conn = new SqlConnection();

conn.ConnectionString = connstring;

conn.Open();

SqlCommand cmd = new SqlCommand(sql, conn);

cmd.ExecuteNonQuery();

conn.Close();

}

public static DataSet GreatDs(string sql)

{

SqlConnection myconn = new SqlConnection(connstring.ToString());

myconn.Open();

SqlDataAdapter mydr = new SqlDataAdapter(sql, myconn);

DataSet myds = new DataSet();

mydr.Fill(myds);

myconn.Close();

return myds;

}

public void MsgBox(string strMsg, string URL)

{

string StrScript;

StrScript = ("<script language=javascript>");

StrScript += ("alert('" + strMsg + "');");

StrScript += ("window.location='" + URL + "';");

StrScript += ("</script>");

System.Web.HttpContext.Current.Response.Write(StrScript);

}

5、数据绑定的后台

public partial class ups_china : System.Web.UI.Page

{

private int CID;

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

CDataBind();

}

}

private void CDataBind()

{

int provice=1,city=1,company=1;

SqlConnection conn = new SqlConnection(db.connstring.ToString());

conn.Open();

string mysql1 = "select * from UPSData where(provice='"+ provice+"' and city='"+city+"' and company='"+company+"')";

SqlDataAdapter sa = new SqlDataAdapter(mysql1, conn);

DataSet ds = new DataSet();

sa.Fill(ds, "table1");

//处理

DataTable dtNew = ds.Tables["table1"].Copy(); //复制dt表数据结构

dtNew.Clear(); //清除数据

foreach (DataRow mydr in ds.Tables["table1"].Rows)

{

dtNew.Rows.Add(mydr.ItemArray);

//dtNew.Rows.Add(ds.Tables["table1"].Rows[i].ItemArray);

}

/*

for (int i = 0; i < dtNew.Rows.Count; i++)

{

dtNew.Rows[i]["id"] = i + 1;

}

*/

//绑定数据

System.Web.UI.WebControls.PagedDataSource ps = new PagedDataSource();

ps.DataSource = dtNew.DefaultView;

ps.AllowPaging = true;

ps.PageSize = 5;

//ps.CurrentPageIndex = curPage - 1;

this.DataList1.DataSource = ps;

this.DataList1.DataBind();

conn.Close();

//绑定完毕

//处理图片

}

}

6、脚本

<script type="text/javascript">

function fatie() {

document.getElementById("ft").style.backgroundColor = '#00ff0f';

document.getElementById("nan").onclick = function () { boy() };

<a onclick="NeatDialog()">显示</a>

7、登录界面后台

protected void LinkButton1_Click(object sender, EventArgs e)

{

Response.Redirect("register.aspx");

}

protected void Button1_Click(object sender, EventArgs e)

{

if (TextBox1.Text == "" || TextBox2.Text == "")

{

Response.Write("<script>aleret('用户名或密码为空');</script>");

}

else if(TextBox3.Text!=Session["vcode"].ToString())

{

Response.Write("<script>alert('验证码输入错误');</script>");

}

else

{

string pu, pw;

pu = TextBox1.Text.Replace("'", "''");

pw = TextBox2.Text.Replace("'", "''");

string sql = "select * from userinfo where usertext='" + pu + "' and userpass='" + pw + "'";

DataTable dt = new DataTable();

dt = db.GreatDs(sql).Tables[0];

if (dt.Rows.Count > 0)

{

Response.Write("<script>alert('您已登录成功');</script>");

Session["memberlogin"] = "ok";

Session["membername"] = pu;

Session["memberpass"] = pw;

Response.Redirect("zhuye.aspx");

}

else

{

Response.Write("<script language=javascript>alert('用户名或者密码错误!');</script>");

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: