I need to provide defaultsand sometimes overrides for items in SQLDataSource's UpdateParameters. I am attempting to do this in a FormView's ItemUpdating and ItemInserting events as follows:
//======================================================================== // FormView1_ItemUpdating: //========================================================================protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) {// not sure if this is the bets place to put this or not? dsDataSource.UpdateParameters["UpdatedTS"].DefaultValue = DateTime.Now.ToString(); dsDataSource.UpdateParameters["UpdatedUserID"].DefaultValue = ((csi.UserInfo)Session["UserInfo"]).QuotaUserID; }
In the example above I am attempting to set new values for the parameters which will replace the existing values.
I have found that using the DefaultValue property works ONLY if there is no current value for the parameter. Otherwise the values I specify are ingnored.
The parameters of an ObjectDataSource provide aValue property but SQLDataSource parameters do not.
How can I provide an override value without needing to place the value in the visible bound form element?
If you can answer this you will be the FIRST person ever to answer one of my questions here!!!
Thanks,
Tony
I figured it out. I still don't know if this is the best way to provide defaults but this works. If anyone has a better method I would appreciate any input
You can use the NewValues property of FormViewUpdateEventArgs and the Values property of FormViewInsertEventArgs
//======================================================================== // FormView1_ItemUpdating: //========================================================================protected void FormView1_ItemUpdating(object sender, FormViewUpdateEventArgs e) {// not sure if this is the bets place to pout this or not? e.NewValues["UpdatedTS"] = DateTime.Now.ToString(); e.NewValues["UpdatedUserID"] = ((csi.UserInfo)Session["UserInfo"]).QuotaUserID; }
No comments:
Post a Comment