Pam,
I don't think that there is any design time support for inserting calculated fields (I'm not fully sure, correct me if wrong anyone). But handling the events of the SqlDataSource is nearly as easy, honestly! Here's how...
In my previous code I said to handle the
RowUpdating event of the GridView. But you don't have a grid view! So a different event needs to be handled instead, with the same code (pretty much) inside the event handler, but this time of your SqlDataSource.
The two events of your SqlDataSource that you need to handle are the
Updating and
Inserting events. To do this, just select the SqlDataSource in Visual Studio (Web Developer) and from the events list on the right hand side double click the Updating event, then the Inserting event. This will add the handlers in the code behind.
In the code behind, do the same calculations on the parameters as before, but in the new event handlers. Something like:
Code:
protected void SqlDataSource1_Inserting(object sender, SqlDataSourceCommandEventArgs e)
{
//concatenating two text fields
e.NewValues["totalcharge"] = txtFirstValue.Text + txtSecondValue.Text;
//using value of other parameters
e.NewValues["totalcharge"] = Convert.ToInt32(e.NewValues["laborhrs"]) * 7.5;
}
protected void SqlDataSource1_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
//concatenating two text fields
e.NewValues["totalcharge"] = txtFirstValue.Text + txtSecondValue.Text;
//using value of other parameters
e.NewValues["totalcharge"] = Convert.ToInt32(e.NewValues["laborhrs"]) * 7.5;
}
This should then calculate the values before they are committed to the database for you. Is this more what you were looking for?
Sorry if this is simple (or not) for you, as I don't know what level you are with ASP.NET.
Rich