When I select a value from the dropdownlist, I like that value to be save in the @TimeZone value that is needed for
InsertCommand="INSERT INTO [Companies] ([TimeZone]) VALUES ( @TimeZone)"
I am not sure how to do this.
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 to I bind the selected value from the dropdownlist (ddlTimeZone) to @TimeZone
I tried:
<asp:DropDownList ID="ddlTimeZone" SelectedValue='<%# Bind("TimeZone") %>' runat="server">
</asp:DropDownList>
But that did not work. NOTE THAT I AM USING THE DROPDOWNLIST WITHIN A GRIDVIEW.
Try this way
var command = new SqlCommand("INSERT INTO [Companies] ([TimeZone]) VALUES ( @TimeZone)", connection);
command.Parameters.Add(new SqlParameter("@TimeZone", valuetopass));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.