How do i pass the SelectedValue/Index of a DropDownList in a GridViews EditItem Template to a Control Parameter?
-
I want a column in my datagrid to be edited by a drop down list. I've put the dropdown list in the edititem template. The contents of the DropDown is sourced from an SQLDataSource And the data bindings set up a two way binding to the "Record" field. I have added this update control parameter Where: "Recorded" is the Parameter name. "gvOutgoing" is the GridView "Selected Value" is the feild i want from the dropdownlist
<UpdateParameters> <asp:ControlParameter name="Recorded" controlid="gvOutgoing" propertyname="SelectedValue"/> <UpdateParameters>
This generates no errors except it passes a NULL value to @Recorded :( Now I originaly thought i should put "ddlRecorded" (the drop down list) in the "controlid" as thats what i want the actaul value of. except it kept giving me this error:Could not find control "ddlRecorded" in ControlParamert "Recorded". Any adivce? Cheers
-
I want a column in my datagrid to be edited by a drop down list. I've put the dropdown list in the edititem template. The contents of the DropDown is sourced from an SQLDataSource And the data bindings set up a two way binding to the "Record" field. I have added this update control parameter Where: "Recorded" is the Parameter name. "gvOutgoing" is the GridView "Selected Value" is the feild i want from the dropdownlist
<UpdateParameters> <asp:ControlParameter name="Recorded" controlid="gvOutgoing" propertyname="SelectedValue"/> <UpdateParameters>
This generates no errors except it passes a NULL value to @Recorded :( Now I originaly thought i should put "ddlRecorded" (the drop down list) in the "controlid" as thats what i want the actaul value of. except it kept giving me this error:Could not find control "ddlRecorded" in ControlParamert "Recorded". Any adivce? Cheers
Because you want to get the value from the dropdownlist then the ControlID should point to this control, not the GridView. However, the dropdownlist is contained inside the GridView, therefore the value of the ControlID will be the uniqueID of the dropdownlist including the id of the containers. So it should be something like
gvOutgoing$ctl02$ddlRecorded
(or you can replace the$
with the:
). There's one more important thing is that the uniqueId of the dropdownlist varies from row to row, so you'll have to update the ControlID dynamically according to which row is being edited. -
Because you want to get the value from the dropdownlist then the ControlID should point to this control, not the GridView. However, the dropdownlist is contained inside the GridView, therefore the value of the ControlID will be the uniqueID of the dropdownlist including the id of the containers. So it should be something like
gvOutgoing$ctl02$ddlRecorded
(or you can replace the$
with the:
). There's one more important thing is that the uniqueId of the dropdownlist varies from row to row, so you'll have to update the ControlID dynamically according to which row is being edited.THANK YOU SO MUCH! I've been pulling my hair out all day over that :D Could you point me to some reference about this so I could understand why it works and possibly find a way to generate that automaticly? Thanks again :)
-
THANK YOU SO MUCH! I've been pulling my hair out all day over that :D Could you point me to some reference about this so I could understand why it works and possibly find a way to generate that automaticly? Thanks again :)