using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
SqlConnection sqlcon;
string strCon = "Data Source=(local);Database=db_04;Uid=sa;Pwd=";
protected void Page_Load(object sender, EventArgs e)
{
sqlcon = new SqlConnection(strCon);
string sqlstr = "select top 1* from tb_Member";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlcon);
DataSet myds = new DataSet();
sqlcon.Open();
myda.Fill(myds, "tb_Member");
DataList1.DataSource = myds;
DataList1.DataBind();
DataRowView mydrv = myds.Tables["tb_Member"].DefaultView[0];
for (int i = 0; i <= DataList1.Items.Count - 1; i++)
{
Label lab = (Label)DataList1.Items[i].FindControl("Label1");
int money = Convert.ToInt32(mydrv["money"]);
lab.Text = money.ToString("¥#,###.00");
}
sqlcon.Close();
}
}
前面都是读取数据,关键代码就是 lab.Text = money.ToString("¥#,###.00"); |