Mark Tabor

Mark Tabor

  • 589
  • 2k
  • 458.8k

ComboBox value is not updated on editing

Apr 12 2016 2:32 PM
I have a simple webform in which i have placed a DevExpress Gridview {<dx:ASPxGridView>}, i did not used code to bind this gridview i just used the designer to bind this gridview to a table , I have two tables in my database, one of my column is having a nature like its value can be any one from Three {i mean its value can be from dropdownlist or comboBox } so i put  Edit Item Template and place combo box in it and bind this combo box from anther table {Second table}
<dx:GridViewDataTextColumn FieldName="GivenTo" VisibleIndex="6">
<EditItemTemplate>
<dx:ASPxComboBox Value='<%# Eval("GivenTo") %>'
ID="ComboBoxProvider" runat="server" Width="325px" TextField="StaffName" ValueField="StaffID" ValueType="System.String" IncrementalFilteringMode="StartsWith" EnableIncrementalFiltering="True" DataSourceID="SqlDataSource2">
</dx:ASPxComboBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
 Now On insertion all other columns are inserted fine except this column and on update the same case all other are updating except this column , I have no code behind code just using the designer below is the over all code of aspx page.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DevExpress.Web.v13.2, Version=13.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v13.2, Version=13.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxGridView ID="ASPxGridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" KeyFieldName="ItemID" >
<Columns>
<dx:GridViewCommandColumn ShowClearFilterButton="True" ShowDeleteButton="True" ShowEditButton="True" ShowNewButtonInHeader="True" VisibleIndex="0">
</dx:GridViewCommandColumn>
<dx:GridViewDataTextColumn FieldName="ItemID" ReadOnly="True" VisibleIndex="1">
<EditFormSettings Visible="False" />
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Item" VisibleIndex="2">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Description" VisibleIndex="3">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="SerialNo" VisibleIndex="4">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="Price" VisibleIndex="5">
</dx:GridViewDataTextColumn>
<dx:GridViewDataTextColumn FieldName="GivenTo" VisibleIndex="6">
<EditItemTemplate>
<dx:ASPxComboBox Value='<%# Eval("GivenTo") %>'
ID="ComboBoxProvider" runat="server" Width="325px" TextField="StaffName" ValueField="StaffID" ValueType="System.String" IncrementalFilteringMode="StartsWith" EnableIncrementalFiltering="True" DataSourceID="SqlDataSource2">
</dx:ASPxComboBox>
</EditItemTemplate>
</dx:GridViewDataTextColumn>
<dx:GridViewDataDateColumn FieldName="GivenOn" VisibleIndex="7">
</dx:GridViewDataDateColumn>
<dx:GridViewDataCheckColumn FieldName="Returned" VisibleIndex="8">
</dx:GridViewDataCheckColumn>
<dx:GridViewDataDateColumn FieldName="ReturnedOn" VisibleIndex="9">
</dx:GridViewDataDateColumn>
<dx:GridViewDataTextColumn FieldName="GivenBy" VisibleIndex="10">
</dx:GridViewDataTextColumn>
</Columns>
<Settings ShowFilterRow="True" />
</dx:ASPxGridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ItemsIssuanceConnectionString %>" DeleteCommand="DELETE FROM [Items] WHERE [ItemID] = @ItemID" InsertCommand="INSERT INTO [Items] ([Item], [Description], [SerialNo], [Price], [GivenTo], [GivenOn], [Returned], [ReturnedOn], [GivenBy]) VALUES (@Item, @Description, @SerialNo, @Price, @GivenTo, @GivenOn, @Returned, @ReturnedOn, @GivenBy)" SelectCommand="SELECT * FROM [Items]" UpdateCommand="UPDATE [Items] SET [Item] = @Item, [Description] = @Description, [SerialNo] = @SerialNo, [Price] = @Price, [GivenTo] = @GivenTo, [GivenOn] = @GivenOn, [Returned] = @Returned, [ReturnedOn] = @ReturnedOn, [GivenBy] = @GivenBy WHERE [ItemID] = @ItemID">
<DeleteParameters>
<asp:Parameter Name="ItemID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Item" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="SerialNo" Type="String" />
<asp:Parameter Name="Price" Type="Int32" />
<asp:Parameter Name="GivenTo" Type="String" />
<asp:Parameter DbType="Date" Name="GivenOn" />
<asp:Parameter Name="Returned" Type="Boolean" />
<asp:Parameter DbType="Date" Name="ReturnedOn" />
<asp:Parameter Name="GivenBy" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Item" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="SerialNo" Type="String" />
<asp:Parameter Name="Price" Type="Int32" />
<asp:Parameter Name="GivenTo" Type="String" />
<asp:Parameter DbType="Date" Name="GivenOn" />
<asp:Parameter Name="Returned" Type="Boolean" />
<asp:Parameter DbType="Date" Name="ReturnedOn" />
<asp:Parameter Name="GivenBy" Type="String" />
<asp:Parameter Name="ItemID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:ItemsIssuanceConnectionString2 %>" SelectCommand="SELECT [StaffName], [StaffID], [Designation] FROM [Staff]"></asp:SqlDataSource>
</div>
</form>
</body>
</html>