您的位置: 旅游网 > 时尚

[冷枫]一个不错的.NET例子_a

发布时间:2020-01-16 22:42:44

数据浏览

对TextBox进行简单绑定

private void Page_Load(object sender, System.EventArgs e)

{

if(!IsPostBack)

{

Session["RecordPos"] = 0;

}

sqlDataAdapter1.Fill(dsStudent1.tbStudentinfo);

this.DataBind();

}

private void btnPrev_Click(object sender, System.EventArgs e)

{

int RecordPos = (int) Session["RecordPos"];

if (RecordPos > 0)

{

RecordPos--;

}

Session["RecordPos"] = RecordPos;

this.DataBind();

}

private void btnNext_Click(object sender, System.EventArgs e)

{

int RecordPos = (int) Session["RecordPos"];

RecordPos++;

if (RecordPos >= dsStudent1.tbStudentinfo.Rows.Count)

{

RecordPos=0;

}

Session["RecordPos"] = RecordPos;

this.DataBind();

}

private void tbID_DataBinding(object sender, System.EventArgs e)

{

int RecordPos = (int) Session["RecordPos"];

tbID.Text = dsStudent1.tbStudentinfo.Rows[RecordPos]["StudentID"].ToString();

}

private void tbName_DataBinding(object sender, System.EventArgs e)

{

int RecordPos = (int) Session["RecordPos"];

tbName.Text = dsStudent1.tbStudentinfo.Rows[RecordPos]["StudentName"].ToString();

}

private void tbScore_DataBinding(object sender, System.EventArgs e)

{

int RecordPos = (int) Session["RecordPos"];

tbScore.Text = dsStudent1.tbStudentinfo.Rows[RecordPos]["Score"].ToString();

}

简单连接的例子

简单绑定一个Label

<%@ Import Namespace="System.Drawing" %> 调入一个命名空间

private void Page_Load(object sender, System.EventArgs e)

{

if(!IsPostBack)

{

ArrayList ar = new ArrayList();

ar.Add("Red");

ar.Add("Blue");

ar.Add("Green");

ar.Add("Orange");

ddlColor.DataSource = ar;

}

this.DataBind();

}

private void btnAdd_Click(object sender, System.EventArgs e)

{

string strSql = "insert into tbUserInfo values('"+tbName.Text+"','"+tbPass.Text+"',"+"'"+trblSex.SelectedItem.Text+"'"+",";

strSql += " '"+cdDate.SelectedDate.ToString()+"','"+tbZhiWei.Text+"','"+tbNotes.Text+"')";

ExcuteSql(strSql);

}

private void ExcuteSql(string strSql)

{

try

{

SqlConnection con = new SqlConnection();

con.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings["DSN"];

con.Open();

//添加纪录...

SqlCommand com = new SqlCommand(strSql,con);

com.ExecuteNonQuery();

con.Close();

Response.Write("<script language='javascript'>alert('插入成功!')</script>");

}

catch(Exception ee)

{

Response.Write("发生错误:"+ee.Message);

}

}

孩子早上咳嗽有痰咳不出怎么办
藤黄健骨丸哪个牌子的好
云香精泡脚的好处
急性扭伤的处理方式
猜你会喜欢的
猜你会喜欢的