您的位置:首页 > 运维架构

dropDownList显示日期格式的数据

2010-01-12 01:00 197 查看
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

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

{
private SqlConnection Conn;
private SqlCommand Comm = new SqlCommand();
private SqlDataAdapter Da = new SqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{

Conn = new SqlConnection("server=localhost;database=Akifatr-Vender;uid=sa;pwd=bpo");
this.Comm.Connection=this.Conn;
this.Da.SelectCommand = this.Comm;
DataTable dt = new DataTable();
dt.Columns.Add("datetime");
this.Comm.CommandText = "select * from second";
this.Da.Fill(dt);
DataTable dt2 = new DataTable();
for (int i = 0; i < dt.Rows.Count; i++)
{
string date = dt.Rows[i]["BatchID"].ToString().Substring(0,4) +"/" +dt.Rows[i]["BatchID"].ToString().Substring(4,2) + "/" + dt.Rows[i]["BatchID"].ToString().Substring(6,2);
dt.Rows[i]["datetime"] = date;
}
//this.DropDownList1.DataTextFormatString = "";
this.GridView1.DataSource = dt;
this.GridView1.DataBind();

this.DropDownList1.DataSource = dt;
this.DropDownList1.DataTextField = "datetime";
this.DropDownList1.DataValueField = "F3";
this.DropDownList1.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dtNew = new DataTable();
DataTable dtOld = new DataTable();
dtOld = (DataTable)this.GridView1.DataSource;
for (int i = 0; i < this.GridView1.Rows.Count; i ++ )
{
CheckBox chb = (CheckBox)this.GridView1.Rows[i].Cells[0].FindControl("CheckBox1");
if(!chb.Checked )
{
//dtOld.Copy(dtNew);
dtOld.Rows[i].ItemArray.CopyTo(dtNew.Rows[i].ItemArray, i);

}
}
this.GridView2.DataSource = dtNew ;
this.GridView2.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;

}

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