How do I bind the selected value of the drop down list and assign it to @TimeZone as currently when I select it, @TimeZone is null.
Here is my code:
Within my page load, I have the following code that assigns value to the drop down:
ddlTimeZone.DataSource = from p in TimeZoneInfo.GetZones()
select new { p.Id };
ddlTimeZone.DataTextField = "Id";
ddlTimeZone.DataValueField = "Id";
ddlTimeZone.DataBind();
Next, within my .aspx file, I have the following:
<EditItemTemplate>
<asp:DropDownList ID="ddlTimeZone" runat="server">
</asp:DropDownList>
</EditItemTemplate>
…..
…..
InsertCommand="INSERT INTO [Companies] ([TimeZone]) VALUES ( @TimeZone)"
<InsertParameters>
<asp:Parameter Name="TimeZone" Type="String" />
</InsertParameters>
Again, what I need to know is how do I assign the value of the selected item in the dropdown list to @TimeZone as currently when I select it, @TimeZone it is null.
I tried
<asp:DropDownList ID="ddlTimeZone" SelectedValue='<%# Bind("TimeZone") %>' runat="server">
</asp:DropDownList>
but that gave the following error message:
‘ddlTimeZone’ has a SelectedValue which is invalid because it does not
exist in the list of items. Parameter name: value
The value returned by
<%# Bind("TimeZone") %>does not exists in the values of the dropdown as you are binding it with the id TimeZoneInfo.GetZones(). Give it some id that exits in data source.Put this statement in code behind.
Edit: Base on assumption that you have TimeZone in data source returned by GetZones()