M
matthew schouppe
I have a datagrid with two columns, the first a normal bound column,
the second is a template column created from a bound column. For the
ItemTemplate of the Template Column, I removed the label and replaced
it with a textbox. Displaying the data from the datasource is not a
problem, however when I change the data in the textbox and click on an
update button (the thought being that multiple rows will have been
changed and I can simply use the update command of the DataAdapter),
the underlying datasource (a DataSet) has HasChanges()=false. What am
I not doing to cause the DataSet to be updated when the user changes
the text in the textbox?
Thanks.
private DataSet ds = new DataSet();
private SqlDataAdapter sda = new SqlDataAdapter("SELECT orderid,
shipname FROM orders", new
SqlConnection("Server=(local)\\NetSDK;Integrated Security=true;Initial
Catalog=Northwind"));
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
sda.Fill(ds, "orders");
DataGrid1.DataSource = ds.Tables["orders"];
DataGrid1.DataBind();
}
}
Private void Button1_Click(object sender, System.EventArgs e)
{
if (ds.HasChanges()) <- ALWAYS FALSE
{
ds.AcceptChanges();
sda.Update(ds);
sda.Fill(ds, "orders");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
}
the second is a template column created from a bound column. For the
ItemTemplate of the Template Column, I removed the label and replaced
it with a textbox. Displaying the data from the datasource is not a
problem, however when I change the data in the textbox and click on an
update button (the thought being that multiple rows will have been
changed and I can simply use the update command of the DataAdapter),
the underlying datasource (a DataSet) has HasChanges()=false. What am
I not doing to cause the DataSet to be updated when the user changes
the text in the textbox?
Thanks.
private DataSet ds = new DataSet();
private SqlDataAdapter sda = new SqlDataAdapter("SELECT orderid,
shipname FROM orders", new
SqlConnection("Server=(local)\\NetSDK;Integrated Security=true;Initial
Catalog=Northwind"));
private void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
sda.Fill(ds, "orders");
DataGrid1.DataSource = ds.Tables["orders"];
DataGrid1.DataBind();
}
}
Private void Button1_Click(object sender, System.EventArgs e)
{
if (ds.HasChanges()) <- ALWAYS FALSE
{
ds.AcceptChanges();
sda.Update(ds);
sda.Fill(ds, "orders");
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
}