Ask a Question related to ASP.NET, Design and Development.
-
Kostia #1
DataGrid easy Edit-Update using ADO.NET/DataGrid functionality C#?
Hi, so I am using built in Edit, Delete, Update i.e.
OnEditCommand="DataGrid1_Edit" OnUpdateCommand="DataGrid1_Update" with
handler
question below in regards to the actual update after edit
//called by the handler deletes row no problem and updates DB no
problem
private void DeleteItem(DataGridCommandEventArgs e)
{
DataRow dr = dsEmployees1.Tables["Employees"].Rows[e.Item.ItemIndex];
dr.Delete();
sqlDataAdapter1.Update(dsEmployees1, "Employees");
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}
public void DataGrid1_Edit(Object sender, DataGridCommandEventArgs E)
{
DataGrid1.EditItemIndex = (int)E.Item.ItemIndex;
DataGrid1.DataBind();
}
//NOW WHAT DO I NEED TO DO HERE TO ACTUALLY UPDATE THE ROW?
//IS THE ONLY WAY TO DO IT IS by getting individual column values and
//constructing SQL statement? IS there a way to call some kind of
update to accept and commit entered changes? done through Edit?
public void DataGrid1_Update(Object sender, DataGridCommandEventArgs
E)
{
DataGrid1.EditItemIndex = (int)E.Item.ItemIndex;
DataRow dr = dsEmployees1.Tables["Employees"].Rows[DataGrid1.EditItemIndex];
sqlDataAdapter1.Update(dsEmployees1, "Employees");
// Rebind the data source to refresh the DataGrid control.
DataGrid1.EditItemIndex = -1;
DataGrid1.DataBind();
}
Kostia Guest
-
Datagrid Edit, Insert & Update Checkbox (ASP.NET Using VB.NET)
Hi you guys. If you could possible help me here. I am quite new to .NET coming over from VB and with limited ASP development. I am having a problem... -
How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the datagrid Update event.
How to add a Dropdown list to a datagrid at runtime (dynamic) without using template columns in ASP.NET and still have the ability to us the... -
Datagrid disappearing on Edit, Update, or Cancel
I had an application developed on asp.net 1.0. I recently moved the application to 2003 server and asp.net 1.1. The application loads fine, but... -
Adding javascript function to update button in datagrid edit row
I'd like to run a javascript function when you click the update button on an edit row, but I've no idea how I'd set it. Can't find any examples,... -
To all Gurus: How can I edit/update a DataGrid in a DataGrid (nested DataGrid)? Possible?
Hello, I am searching the whole Internet for a good example how to edit/update a DataGrid in a DataGrid (nested DataGrid). I know how to... -
Scott Mitchell [MVP] #2
Re: DataGrid easy Edit-Update using ADO.NET/DataGrid functionality C#?
> //NOW WHAT DO I NEED TO DO HERE TO ACTUALLY UPDATE THE ROW?
> //IS THE ONLY WAY TO DO IT IS by getting individual column values and
> //constructing SQL statement?
Yes. This is precisely what you have to do. For a look at an article
that builds an editable DataGrid, see:
An Extensive Examination of the DataGrid Web Control: Part 6
[url]http://aspnet.4guysfromrolla.com/articles/071002-1.aspx[/url]
Happy Programming!
--
<shameless plug>
For more information on the DataGrid, DataList, and Repeater controls,
consider picking up a copy of my latest book:
ASP.NET Data Web Controls
[url]http://www.amazon.com/exec/obidos/ASIN/0672325012/4guysfromrollaco[/url]
</shameless plug>
Happy Programming!
Scott Mitchell
[email]mitchell@4guysfromrolla.com[/email]
[url]http://www.4GuysFromRolla.com[/url]
[url]http://www.ASPFAQs.com[/url]
[url]http://www.ASPMessageboard.com[/url]
* When you think ASP, think 4GuysFromRolla.com!
Scott Mitchell [MVP] Guest



Reply With Quote

