I have a details view with several parameters set up in myasp.net 2.0 code, I want to add a parameter before the sql parameter is executed. I need to use the find control of the details view because I am using items/edit item templates in my details view control.
I tried this(see below) as well as the detailsview item command event args to no avail. It doesn't see the other parameters that have already been declared in my asp.net code. I don't want to have to declare all my varibles that are already in my asp.net code. I just want to add another parameter.
Sub InsertNew(ByVal sender As Object, ByVal e As DetailsViewInsertEventArgs) _
Handles dvEvents.ItemInsertingDim dvr As DetailsViewRow
For Each dvr In dvEvents.Rows
Dim CatIDup As Integer = CType(dvr.FindControl("ddlCat"), DropDownList).SelectedValue
sdsevents.InsertParameters.Add("evCatID", CatIDup)
sdsevents.Insert()
Handle the sdsevents.Inserting event.
e.Command.Parameters.Add("@.evCatID",SqlDbType.Int).Value={something}
Also, in your prior code, it's confusing, because you are iterating a set of rows in dvr, and dvr hasn't been set. Even if it was, why would you want to add a parameter for each row?
|||I tried what you suggested and i get sqldbtype is not declared. see below
As far as iiterating through the rows, I could not find a better way to do that if i did not iterate the rows i would get the error
about my dvr not being set if i did the for each i did not get that error.
I am happy to hear a better suggestion of how to do this.
Thanks
Sub InsertNew(ByVal senderAsObject,ByVal eAs SqlDataSourceCommandEventArgs) _
Handles sdsevents.Inserting
Dim dvrAs DetailsViewRow
ForEach dvrIn dvEvents.Rows
' Find the Selected Category Name ID Value
Dim CatIDupAsInteger =CType(dvr.FindControl("ddlCat"), DropDownList).SelectedValue
e.Command.Parameters.Add("@.evCatID",SqlDbType.Int).Value={CatIDup}
NextEndSub
|||Sub InsertNew(ByVal senderAsObject,ByVal eAs SqlDataSourceCommandEventArgs) _Handles sdsevents.Inserting
Dim dvAs DetailsView=detailsview1
' Find the Selected Category Name ID Value
Dim CatIDupAsInteger =CType(dv.FindControl("ddlCat"), DropDownList).SelectedValue
e.Command.Parameters.Add("@.evCatID",System.Data.SqlDbType.Int).Value=CatIDup
EndSub
That assumes your detailsview is called detailsview1.
You can also do it from the detailsview events, but you need to reference the parameter collection that is passed to you. In the ItemInserting event, it would be e.Values. In the ItemUpdating event, it would be e.NewValues. Normally I would declaritively define the parameter (In design view... To assign the type, nullability, default value, etc etc). Then I would either set the value in e.Values/e.NewValues or e.Command.Parameters("@.evCatID").Value= to set the value of the already existing parameter.
|||I got it I did it this way
thanks for your help!!
PublicSub InsertNew(ByVal senderAsObject,ByVal eAs DetailsViewInsertEventArgs) _
Handles dvEvents.ItemInserting
Dim dvAs DetailsView = dvEvents
' 'Find the Selected Category Name ID Value
Dim CatIDupAsInteger =CType(dv.FindControl("ddlCat"), DropDownList).SelectedValue
sdsevents.InsertParameters.Add("evCatID", CatIDup)EndSub
No comments:
Post a Comment