I have a gridview. In this i have a templatefield with a DropDownList (DDL in EditItemTemplate mode, label in ItemTemplate mode). When i hit edit on of of the detailsview's rows i can select any value from the DDL (the DDL is populated from a sqldatasource), but if i try to execute the update, it fails, because it thinks i didn't supply the data...
Here is the exact error (the DB refuse NULL data):
Cannot insert the value NULL into column 'status', table 'gyumolcs.dbo.orders'; column does not allow nulls. UPDATE fails. The statement has been terminated.
Here is the code for the gridview:
<!-- language: c# -->
<asp:SqlDataSource ID="orderadminSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>"
SelectCommand="SELECT orders.ID, aspnet_Users.UserName, orders.quantity AS Quantity, product.name AS Product, status.name AS Status, orders.date AS Date FROM orders INNER JOIN product ON orders.ordertype = product.ID INNER JOIN status ON orders.status = status.ID INNER JOIN aspnet_Users ON orders.userid = aspnet_Users.UserId ORDER BY date"
DeleteCommand="DELETE FROM orders WHERE (ID = @ID)"
UpdateCommand="UPDATE orders SET status = @status WHERE (ID = @ID)">
<DeleteParameters>
<asp:Parameter Name="ID" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="status" />
<asp:Parameter Name="ID" />
</UpdateParameters>
</asp:SqlDataSource><asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="orderadminSqlDataSource" DataKeyNames="ID" Width="608px"
AllowPaging="True" AllowSorting="True" PageSize="15">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID"
SortExpression="ID" InsertVisible="False" ReadOnly="True" >
<ItemStyle HorizontalAlign="Right" />
</asp:BoundField>
<asp:BoundField DataField="UserName" HeaderText="Felhasználónév"
SortExpression="UserName" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Quantity" HeaderText="Mennyiség (kg)"
SortExpression="Quantity" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Product" HeaderText="Termék"
SortExpression="Product" >
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="Rendelés státusz" SortExpression="status">
<EditItemTemplate>
<!--<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Status") %>'></asp:TextBox>-->
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="statustypeDDLSqlDataSource" DataTextField="name"
DataValueField="ID">
</asp:DropDownList>
<asp:SqlDataSource ID="statustypeDDLSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>"
SelectCommand="SELECT [ID], [name] FROM [status]">
</asp:SqlDataSource>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="status" runat="server" Text='<%# Bind("Status") %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" />
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
<asp:BoundField DataField="Date" HeaderText="Dátum" SortExpression="Date" />
</Columns>
<PagerSettings PageButtonCount="15" Mode="NumericFirstLast" />
</asp:GridView>
And here is the orderadminSqlDataSource's code (the gridview's datasource)
<!-- language: c# -->
<asp:SqlDataSource ID="orderadminSqlDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:dotnetConnectionString %>"
SelectCommand="SELECT orders.ID, aspnet_Users.UserName, orders.quantity AS Quantity, product.name AS Product, status.name AS Status, orders.date AS Date FROM orders INNER JOIN product ON orders.ordertype = product.ID INNER JOIN status ON orders.status = status.ID INNER JOIN aspnet_Users ON orders.userid = aspnet_Users.UserId ORDER BY date"
DeleteCommand="DELETE FROM orders WHERE (ID = @ID)"
UpdateCommand="UPDATE orders SET status = @status WHERE (ID = @ID)">
<DeleteParameters>
<asp:Parameter Name="ID" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="status" />
<asp:Parameter Name="ID" />
</UpdateParameters>
</asp:SqlDataSource>
Please help me, i can't figure out the problem. Thanks in advance!