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;
Remember Me
a@href@title, strike
Powered by: newtelligence dasBlog 2.0.7226.0
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
© Copyright 2008, Andrew Robinson
E-mail