views:

89

answers:

0

I'm trying to subclass the .NET 2.0 Gridview control and implement a custom Update to perform when "edit" is clicked; however I get the following cryptic error message: "An unexpected error has occurred." I'm trying to access our db logs to see if its failing there, but until i get access, i cannot debug the issue. Here are snippets of my code:

In the WebPart CreateChildControls method:

sqlDataSource.UpdateCommand = "dbo.UpdateInvoiceData";
sqlDataSource.UpdateCommandType = SqlDataSourceCommandType.StoredProcedure;
sqlDataSource.UpdateParameters.Add(new Parameter("month", DbType.Int32, "2"));
sqlDataSource.UpdateParameters.Add(new Parameter("year", DbType.Int32, "2010"));
this.Controls.Add(sqlDataSource);
EditGridView edv = new EditGridView(sqlDataSource);
this.Controls.Add(edv);

In the EditGridView webcontrol:

OnLoad:

this.AutoGenerateEditButton = true;
this.AutoGenerateColumns = true;
string[] keyNames = { "Name" };
this.DataKeyNames = keyNames;
this.EnableViewState = true;
this.DataSourceID = sqlDataSource.ID;
this.DataBind();

protected override void OnRowUpdating(GridViewUpdateEventArgs e)
{
   try
   {
      sqlDataSource.UpdateParameters.Add(new Parameter("ExtraParamName", DbType.Int32, e.NewValues["ExtraParamName"].ToString()));
      sqlDataSource.UpdateParameters.Add(new Parameter("Name", DbType.String, e.NewValues["Name"].ToString()));
      sqlDataSource.UpdateParameters.Add(new Parameter("spUser", DbType.String, "test"));

    }
    catch (Exception ex)
    {
       this.Page.Response.Write("Error occurred while updating the record.  " + ex.Message);
    }
}