I have a Combobox where the list can be edited and I'm trying to update the text which is read from 2 database tables but I'm having trouble doing that.
Customer Table: CustomerID and Customername (Lookup Table)
Product Table: Customer (Contains the CustomerID from Customer Table)
This is my code:
Code:
<asp:FormView ID="FormView2" runat="server" DataSourceID="SqlDataSource1">
<EditItemTemplate>
<table class="contentEdit">
<tr>
<td>
<asp:TextBox ID="TextBoxDescription" runat="server" Text='<%# Bind("Description") %>' /></td>
<td>
<asp:ComboBox ID="ComboBoxCategory" runat="server" AppendDataBoundItems="True"
AutoCompleteMode="SuggestAppend" AutoPostBack="False" SelectedValue='<%# Bind("Category") %>'
DataSourceID="SqlDataSourceCategory" DataTextField="CategoryName" AllowCustomText="True"
DataValueField="CategoryID" MaxLength="0" style="display: inline;">
<asp:ListItem Text="Select/Enter New Value" Value="" />
</asp:ComboBox>
<asp:SqlDataSource ID="SqlDataSourceCategory" runat="server"
ConnectionString="<%$ ConnectionStrings:ProdConnectionString %>"
SelectCommand="SELECT * FROM [Category]"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"></asp:SqlDataSource>
</td>
</tr>
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" CssClass="button" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" CssClass="button"/>
<br /> <br />
</td>
</tr>
</table>
</EditItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" CancelSelectOnNullParameter="false"
ConnectionString="<%$ ConnectionStrings:ProdConnectionString %>"
SelectCommand="SELECT * FROM [Products]"
UpdateCommand="UPDATE Products SET [ProdNum] = @ProdNum, [Description] = @Description, [Category] = @CategoryValue
WHERE ProductID = @ProductID;
UPDATE Category Set CategoryName = @CategoryName
WHERE CategoryID= @Category;">
<UpdateParameters>
<asp:Parameter Name="ProductID" Type="Int32" ConvertEmptyStringToNull="true" />
<asp:Parameter Name="ProdNum" Type="String" ConvertEmptyStringToNull="true" />
<asp:Parameter Name="Description" Type="String" ConvertEmptyStringToNull="true" />
<asp:Parameter Name="Category" Type="String" ConvertEmptyStringToNull="true" />
<asp:ControlParameter ControlID="FormView2$ComboBoxCategory" Name="CategoryName" PropertyName="SelectedItem.Text" Type="String" />
<asp:ControlParameter ControlID="FormView2$ComboBoxCategory" Name="CategoryValue" PropertyName="SelectedItem.Value" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
I tried :
<asp:ControlParameter ControlID="FormView2$ComboBoxCategory" Name="CategoryName" PropertyName="SelectedText" Type="String" />
<asp:ControlParameter ControlID="FormView2$ComboBoxCategory" Name="CategoryValue" PropertyName="SelectedValue" Type="Int32" />
But got the error:
'AjaxControlToolkit.ComboBox' does not contain a property with the name 'SelectedText'
I'm really stuck and can't find a way to update a comboBbox.
Thanks so much for your help.