private void Page_Load(object sender, System.EventArgs e)
{
string strCn="Data Source=sprogram;uid=develop;pwd=xx;Initial Catalog=new_ks";
string strSQL=" SELECT TOP 10 person_name "
+" FROM dbo.person ";
SqlDataAdapter sadTest=new SqlDataAdapter(strSQL,strCn);
DataSet dsTest=new DataSet();
sadTest.Fill(dsTest);
DataView dvTest=dsTest.Tables[0].DefaultView;
DataGrid1.DataSource=dvTest;
DataGrid1.DataBind();
Session["dvTest"]=dvTest;
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
DataView dvTest=(DataView)Session["dvTest"];
dvTest.Table.Rows[0][0]="aaaa";
DataGrid1.DataSource=dvTest;
DataGrid1.DataBind();
}
{
string strCn="Data Source=sprogram;uid=develop;pwd=xx;Initial Catalog=new_ks";
string strSQL=" SELECT TOP 10 person_name "
+" FROM dbo.person ";
SqlDataAdapter sadTest=new SqlDataAdapter(strSQL,strCn);
DataSet dsTest=new DataSet();
sadTest.Fill(dsTest);
DataView dvTest=dsTest.Tables[0].DefaultView;
DataGrid1.DataSource=dvTest;
DataGrid1.DataBind();
Session["dvTest"]=dvTest;
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void Button1_Click(object sender, System.EventArgs e)
{
DataView dvTest=(DataView)Session["dvTest"];
dvTest.Table.Rows[0][0]="aaaa";
DataGrid1.DataSource=dvTest;
DataGrid1.DataBind();
}
Page_Load中应该加
if(!Page.IsPostBack)
{
}
然后在按钮中应循环读取TextBox控件的值,填到DataView中。
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面 if (!IsPostBack)
{
ViewState["SortField"]="courseID";
BindGrid();
}
} #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.DataGrid1.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.DataGrid1_PageIndexChanged);
this.DataGrid1.SortCommand += new System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.DataGrid1_SortCommand);
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Button3.Click += new System.EventHandler(this.Button3_Click);
this.Load += new System.EventHandler(this.Page_Load); }
#endregion private void BindGrid()
{
SqlConnection qiang=new SqlConnection("server=localhost;uid=sa;pwd=;database=course");
SqlDataAdapter qiang1=new SqlDataAdapter(("select * from tijiao"),qiang);
DataSet ds = new DataSet();
qiang1.Fill(ds,"tijiao");
DataView dv = new DataView();
dv=ds.Tables["tijiao"].DefaultView;
dv.Sort = (string)ViewState["SortField"];
DataGrid1.DataSource=dv;
DataGrid1.DataBind();
} private void DataGrid1_SortCommand(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
{
ViewState["SortField"] = (string)e.SortExpression;
BindGrid();
} private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid();
} private void Button1_Click(object sender, System.EventArgs e)
{
DataGrid1.EditItemIndex = -1;
SqlConnection qiang=new SqlConnection("server=localhost;uid=sa;pwd=;database=course");
SqlDataAdapter qiang1=new SqlDataAdapter(("select * from tijiao where sno like '%" + sno.Text + "%'"),qiang);
DataSet ds = new DataSet();
qiang1.Fill(ds,"tijiao");
DataView dv = new DataView();
dv=ds.Tables["tijiao"].DefaultView;
DataGrid1.DataSource=dv;
DataGrid1.DataBind(); }
}
反正对于客户端来说都是一样的最终都是Input!