繁体   English   中英

asp.net 下拉列表选择的值

[英]asp.net dropdownlist selected value

当我从下拉列表中选择一个值时,我喜欢将该值保存在所需的 @TimeZone 值中

     InsertCommand="INSERT INTO [Companies] ([TimeZone]) VALUES ( @TimeZone)"

我不知道该怎么做。

这是我的代码:

在我的页面加载中,我有以下代码为下拉列表赋值:

    ddlTimeZone.DataSource = from p in TimeZoneInfo.GetZones()
                             select new { p.Id };
    ddlTimeZone.DataTextField = "Id";
    ddlTimeZone.DataValueField = "Id";             
    ddlTimeZone.DataBind();

接下来,在我的 .aspx 文件中,我有以下内容:

    <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> 

同样,我需要知道的是如何将下拉列表 (ddlTimeZone) 中的选定值绑定到 @TimeZone

我试过:

      <asp:DropDownList ID="ddlTimeZone" SelectedValue='<%# Bind("TimeZone") %>' runat="server">
      </asp:DropDownList>

但这没有用。 请注意,我在 GridView 中使用下拉列表。

试试这个方法

var command = new SqlCommand("INSERT INTO [Companies] ([TimeZone]) VALUES ( @TimeZone)", connection);
command.Parameters.Add(new SqlParameter("@TimeZone", valuetopass));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM