I am tearing my hair out over a problem with drop-down lists. I am trying to use one in my main prject but have had such problems that I have created a test page just containing a single drop-down list to see fi I can figure out the problem.
Basically I have a test table with 2 fields: DDL_Test_ID (ID field, autogenerated) and TestValue (varchar 50)
On my page I have a formview which contains a dropdown list in the InsertItem template which I want to use to write a value into the TestValue field in my database table. However when I run the page and click insert I get the following error page:
Cannot insert the value NULL into column 'TestValue', table 'WellManClinics.dbo.DDLtest'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I am obviously missing somethign very obvious here but for the life of me I can't figure it out. Can anyone help? See code below:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DDL_Test.aspx.vb" Inherits="DDL_Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="<head runat="server">
<title>Drop-down List test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="DDL_Test_ID"
DataSourceID="SqlDataSource1" DefaultMode="Insert">
<EditItemTemplate>
DDL_Test_ID:
<asp:Label ID="DDL_Test_IDLabel1" runat="server"
Text='<%# Eval("DDL_Test_ID") %>' />
<br />
TestValue:
<asp:TextBox ID="TestValueTextBox" runat="server"
Text='<%# Bind("TestValue") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
TestValue:
<aspropDownList ID="TestValue" runat="server"
SelectedIndex='<%# Bind("DDL_Test_ID") %>' AutoPostBack="True">
<asp:ListItem Value="V1">Value 1</asp:ListItem>
<asp:ListItem Value="V2">Value 2</asp:ListItem>
<asp:ListItem Value="V3">Value 3</asp:ListItem>
<asp:ListItem Value="V4">Value 4</asp:ListItem>
<asp:ListItem Value="V5">Value 5</asp:ListItem>
</aspropDownList>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
DDL_Test_ID:
<asp:Label ID="DDL_Test_IDLabel" runat="server"
Text='<%# Eval("DDL_Test_ID") %>' />
<br />
TestValue:
<asp:Label ID="TestValueLabel" runat="server" Text='<%# Bind("TestValue") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:WellManClinicsConnectionString %>"
DeleteCommand="DELETE FROM [DDLtest] WHERE [DDL_Test_ID] = @original_DDL_Test_ID AND [TestValue] = @original_TestValue"
InsertCommand="INSERT INTO [DDLtest] ([TestValue]) VALUES (@TestValue)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [DDL_Test_ID], [TestValue] FROM [DDLtest]"
UpdateCommand="UPDATE [DDLtest] SET [TestValue] = @TestValue WHERE [DDL_Test_ID] = @original_DDL_Test_ID AND [TestValue] = @original_TestValue">
<DeleteParameters>
<asparameter Name="original_DDL_Test_ID" Type="Int32" />
<asparameter Name="original_TestValue" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="TestValue" Type="String" />
<asparameter Name="original_DDL_Test_ID" Type="Int32" />
<asparameter Name="original_TestValue" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="TestValue" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
Basically I have a test table with 2 fields: DDL_Test_ID (ID field, autogenerated) and TestValue (varchar 50)
On my page I have a formview which contains a dropdown list in the InsertItem template which I want to use to write a value into the TestValue field in my database table. However when I run the page and click insert I get the following error page:
Cannot insert the value NULL into column 'TestValue', table 'WellManClinics.dbo.DDLtest'; column does not allow nulls. INSERT fails.
The statement has been terminated.
I am obviously missing somethign very obvious here but for the life of me I can't figure it out. Can anyone help? See code below:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="DDL_Test.aspx.vb" Inherits="DDL_Test" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
<html xmlns="<head runat="server">
<title>Drop-down List test</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:FormView ID="FormView1" runat="server" DataKeyNames="DDL_Test_ID"
DataSourceID="SqlDataSource1" DefaultMode="Insert">
<EditItemTemplate>
DDL_Test_ID:
<asp:Label ID="DDL_Test_IDLabel1" runat="server"
Text='<%# Eval("DDL_Test_ID") %>' />
<br />
TestValue:
<asp:TextBox ID="TestValueTextBox" runat="server"
Text='<%# Bind("TestValue") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
TestValue:
<aspropDownList ID="TestValue" runat="server"
SelectedIndex='<%# Bind("DDL_Test_ID") %>' AutoPostBack="True">
<asp:ListItem Value="V1">Value 1</asp:ListItem>
<asp:ListItem Value="V2">Value 2</asp:ListItem>
<asp:ListItem Value="V3">Value 3</asp:ListItem>
<asp:ListItem Value="V4">Value 4</asp:ListItem>
<asp:ListItem Value="V5">Value 5</asp:ListItem>
</aspropDownList>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
DDL_Test_ID:
<asp:Label ID="DDL_Test_IDLabel" runat="server"
Text='<%# Eval("DDL_Test_ID") %>' />
<br />
TestValue:
<asp:Label ID="TestValueLabel" runat="server" Text='<%# Bind("TestValue") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:WellManClinicsConnectionString %>"
DeleteCommand="DELETE FROM [DDLtest] WHERE [DDL_Test_ID] = @original_DDL_Test_ID AND [TestValue] = @original_TestValue"
InsertCommand="INSERT INTO [DDLtest] ([TestValue]) VALUES (@TestValue)"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT [DDL_Test_ID], [TestValue] FROM [DDLtest]"
UpdateCommand="UPDATE [DDLtest] SET [TestValue] = @TestValue WHERE [DDL_Test_ID] = @original_DDL_Test_ID AND [TestValue] = @original_TestValue">
<DeleteParameters>
<asparameter Name="original_DDL_Test_ID" Type="Int32" />
<asparameter Name="original_TestValue" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="TestValue" Type="String" />
<asparameter Name="original_DDL_Test_ID" Type="Int32" />
<asparameter Name="original_TestValue" Type="String" />
</UpdateParameters>
<InsertParameters>
<asparameter Name="TestValue" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>