It's definitely not like saving a dataset in a windows app. You have to pull
the edited values off of your grid and update them one at a time. Use the
edititemTemplate of the grid to set up text boxes and whatever for the user
to modify the values. Then in the update command pull the values from those
textboxes and pass to your database through stored procredures.
//datagrid html
<EDITITEMTEMPLATE>
<ASP:TEXTBOX class="text" id="txtEditCatTitle" runat="server" text='<%#
DataBinder.Eval(Container.DataItem, "dc_title")%>' size="30">
</ASP:TEXTBOX>
</EDITITEMTEMPLATE>
//the update command
private void dgCats_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Admin data = new Admin();
int ID = Convert.ToInt32(e.Item.Cells[0].Text);
string Title = ((TextBox) e.Item.FindControl("txtEditCatTitle")).Text;
data.UpdateDocumentCategory(ID, Title);
//reset the form
dgCats.EditItemIndex = -1;
RefreshGrids();
}
"Nikhil Patel" wrote:
Hi,
I bind a grid to a DataView object. I lose the reference to the underlying
DataTable and the DataSet in a postback.
Here is the code. Page_Load works fine and I am able to see the rows in grid
and edit them. But I don't know how to save the data back to the database
when the user clicks on a Button. Thanks.
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
{
string sFieldName = Request.QueryString["FieldName"];
DataSet dataSetLookup = (DataSet) Application["Lookup"];
DataView viewLookup =
dataSetLookup.Tables["ProposalLookup"].DefaultView;
viewLookup.RowFilter = "FieldName = '"+sFieldName+"'";
viewLookup.Sort = "FieldValue";
gridLookup.DataSource = viewLookup;
gridLookup.DataBind();
}
}