Hello Everyone...
I have a problem Binding ComboBoxes. Here is my example:-
I have a table in my database which has a list of company vehicles. Another table has a complete list of any vehicles ID, vehicleMake, vehicleModel, vehicleEngineSize.
In edit mode the company vehicles can be changed colour etc. Also there are three comboboxes. 1: List all the possible Makes. Ford, Volvo etc. The second all Models and the final one all engine sizes.
So that the user is only able to select the correct combination the boxes load by EnableLoadOnDemand. I used the Telerik help file here: Help File
Ok so my problem comes when I want to update any possible changes.
As you can see in the first example there is no SelectedValue="<%# bind('vehicleModel') %>" in the above template. If I include this i get the error:-
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control
But without the Bind the changes obviously are not returned to the table
My question therefore is how do I rebind the changes back to the database. I think the error above is because I am calling the Bind to early but I'm not sure... Hopefully someone will have the answer as this problem is driving me mad!!!
Thanx for looking. Marcus
PS Can any code suggestions be in VB pls
I have a problem Binding ComboBoxes. Here is my example:-
I have a table in my database which has a list of company vehicles. Another table has a complete list of any vehicles ID, vehicleMake, vehicleModel, vehicleEngineSize.
In edit mode the company vehicles can be changed colour etc. Also there are three comboboxes. 1: List all the possible Makes. Ford, Volvo etc. The second all Models and the final one all engine sizes.
So that the user is only able to select the correct combination the boxes load by EnableLoadOnDemand. I used the Telerik help file here: Help File
Ok so my problem comes when I want to update any possible changes.
THIS WORKES:-
<
telerik:GridTemplateColumn
DataField
=
"vehicleModel"
HeaderText
=
"vehicleModel"
SortExpression
=
"vehicleModel"
UniqueName
=
"vehicleModel"
>
<
EditItemTemplate
>
<
telerik:RadComboBox
ID
=
"rcb_vehicleModel"
runat
=
"server"
Text='<%#DataBinder.Eval(Container.DataItem,"vehicleModel")%>' EnableLoadOnDemand="True" OnItemsRequested="rcb_vehicleModel_ItemsRequested" AutoPostBack="true">
</
telerik:RadComboBox
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lbl_vehicleModel"
runat
=
"server"
Text='<%# Eval("vehicleModel") %>'></
asp:Label
>
</
ItemTemplate
>
<
HeaderStyle
Width
=
"6em"
/>
</
telerik:GridTemplateColumn
>
DOES NOT WORK:-
<
telerik:GridTemplateColumn
DataField
=
"vehicleModel"
HeaderText
=
"vehicleModel"
SortExpression
=
"vehicleModel"
UniqueName
=
"vehicleModel"
>
<
EditItemTemplate
>
<
telerik:RadComboBox
ID
=
"rcb_vehicleModel"
runat
=
"server"
DataSourceID
=
"sqlds_vehicleModel"
DataTextField
=
"vehicleModel"
DataValueField
=
"vehicleMake"
SelectedValue="<%# bind('vehicleModel') %>" AutoPostBack="True">
</
telerik:RadComboBox
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lbl_vehicleModel"
runat
=
"server"
Text='<%# Eval("vehicleModel") %>'></
asp:Label
>
</
ItemTemplate
>
<
HeaderStyle
Width
=
"6em"
/>
</
telerik:GridTemplateColumn
>
As you can see in the first example there is no SelectedValue="<%# bind('vehicleModel') %>" in the above template. If I include this i get the error:-
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control
But without the Bind the changes obviously are not returned to the table
Protected Sub rcb_vehicleModel_ItemsRequested(ByVal sender As Object, ByVal e As RadComboBoxItemsRequestedEventArgs)
Dim editedItem As GridEditableItem = CType(CType(sender, RadComboBox).NamingContainer, GridEditableItem)
Dim ddl_make As RadComboBox = DirectCast(editedItem.FindControl("rcb_vehicleMake"), RadComboBox)
Dim ddl_model As RadComboBox = DirectCast(editedItem.FindControl("rcb_vehicleModel"), RadComboBox)
Dim ddl_vehicleEngine As RadComboBox = DirectCast(editedItem.FindControl("rcb_vehicleEngineSize"), RadComboBox)
Dim SQLstr As String
SQLstr = "SELECT DISTINCT vehicleModel FROM dbo.vehicleTypes WHERE (vehicleMake = '" & ddl_make.SelectedValue.ToString & "')"
' change the data source for ContactTitle with custom code here
sqlds_vehicleModel.SelectCommand = SQLstr
ddl_model.DataValueField = "vehicleModel"
ddl_model.DataTextField = "vehicleModel"
ddl_model.DataSource = sqlds_vehicleModel
ddl_model.DataBind() '********@ERROR HERE AS ABOVE: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control
End Sub
My question therefore is how do I rebind the changes back to the database. I think the error above is because I am calling the Bind to early but I'm not sure... Hopefully someone will have the answer as this problem is driving me mad!!!
Thanx for looking. Marcus
PS Can any code suggestions be in VB pls