Monday, January 09, 2006
« .NET Symmetric Encryption | Main | Emailing Exceptions from ASP.NET »

I came up with a slightly different way of handling the insert code in my previous "Insert Rows with a GridView" posting. Instead of calling my data layer directly from my code behind page, I pass the values to my ObjectDataSource control and allow it to handle the inserts. Not a major change but a bit more consistent in that the ODS handles all of my CRUD logic and I never call my data layer directly.

My previous post:
http://blog.binaryocean.com/PermaLink,guid,eca3c5a1-08c1-4226-bfb5-d36fddaef93b.aspx

The complete Solution for this modified version:
http://download.binaryocean.com/GridViewInsertSolution2.zip

Make sure to wire up the OnInserting event in the ODS control:
OnInserting="ObjectDataSourceMain_Inserting"

protected void GridViewMain_RowCommand(object sender, GridViewCommandEventArgs e)

{

    //  handle the save button on the footer row.

    if (e.CommandName == "Save")

    {

        ObjectDataSourceMain.Insert();      

    }

}

 

protected void ObjectDataSourceMain_Inserting(object sender, ObjectDataSourceMethodEventArgs e)

{

    //  on insert, pass the values from the footer controls.

    e.InputParameters["LocationCode"] = ((TextBox)GridViewMain.FooterRow.FindControl("TextBoxCode")).Text;

    e.InputParameters["LocationDescription"] = ((TextBox)GridViewMain.FooterRow.FindControl("TextBoxDescription")).Text;

    e.InputParameters["LocationIsActive"] = ((CheckBox)GridViewMain.FooterRow.FindControl("CheckBoxIsActive")).Checked;

}

 

kick it on DotNetKicks.com   Monday, January 09, 2006 8:42:19 AM (Pacific Standard Time, UTC-08:00)  #    Disclaimer  |  Comments [4]  |