Re: GridView, DataSource, RowUpdating, e.OldValues and e.NewValues
hi,
thanks a lot for the rowupdating.it working fine.but if i use this code
for customer database.after i clicking the update button im getting
errors .actually im new to this .net plz solve my problem.
here's my code
public void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable table = new DataTable("customers");
Session["Table"] = table;
string connectionstring =
"server=.;database=Northwind;uid=sa;pwd=";
string commandtext;
commandtext = "select * from customers ";
SqlConnection myconnection = new
SqlConnection(connectionstring);
SqlDataAdapter mycommand = new SqlDataAdapter(commandtext,
myconnection);
DataSet ds = new DataSet();
mycommand.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();
}
}
protected void GridView1_RowUpdating(object sender,
GridViewUpdateEventArgs e)
{
DataTable dataTable = Session["Table"] as DataTable;
for (int i = 0; i < dataTable.Columns.Count; i++)
{
DataControlFieldCell
cell = GridView1.Rows[e.RowIndex].Cells[i] as
DataControlFieldCell;
GridView1.Columns[i].ExtractValuesFromCell(e.NewValues,
cell, DataControlRowState.Edit, true);
}
foreach (string key in e.NewValues.Keys)
{
//response.write("<br/>" + key + ": " + e.NewValues[key]);
dataTable.Rows[e.RowIndex][key] = e.NewValues[key];
}
GridView1.EditIndex = -1;
Session["Table"] = dataTable;
GridView1.DataSource = dataTable;
GridView1.DataBind();
}
error is in this line:
DataControlFieldCell cell = GridView1.Rows[e.RowIndex].Cells[i] as
DataControlFieldCell;
error is:
Specified argument was out of the range of valid values.
Parameter name: index
plz tel me
thanks
*** Sent via Developersdex http://www.developersdex.com ***
Date:Wed, 11 Jul 2007 16:31:23 -0700
Author:
|