SQLDATASOURCE - 使用组合框

时间:2016-12-06 04:47:01

标签: c# asp.net datagridview sqldatasource datagridcomboboxcolumn

我在datagridview中更新。
我显示一个组合框并在我的数据源datatextfield和datavalue字段中选择。
当我创建更新命令时,如何选择我的值而不是我的文本?

        UpdateCommand="UPDATE Properties SET AgentID =@agent, PropertyType =@type, City =@city, Rooms =@rooms, AreaSize =@surface, Price =@price, Bathrooms =@bathrooms, Description =@description, Address =@address WHERE [PropertyID]=@PropertyID" >

以下是我为我的一个组合框尝试的内容:

 <asp:TemplateField HeaderText="DescriptionType" SortExpression="DescriptionType">
 <EditItemTemplate>
     <asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="SqlDataSourceType" DataTextField="DescriptionType" DataValueField="TypeID" AutoPostBack="True"  SelectedValue='<%#Bind("TypeID")%>'>
     </asp:DropDownList>
  <asp:SqlDataSource ID="SqlDataSourceType" runat="server" ConnectionString="<%$ ConnectionStrings:RealEstateConnectionString %>" ProviderName="<%$ ConnectionStrings:RealEstateConnectionString.ProviderName %>" SelectCommand="SELECT DISTINCT * FROM [Types]"></asp:SqlDataSource>
 </EditItemTemplate>
     <ItemTemplate>
        <asp:Label ID="Label6" runat="server" Text='<%# Bind("DescriptionType") %>'></asp:Label>
      </ItemTemplate>
       </asp:TemplateField>

          <UpdateParameters>             
          <asp:Parameter Name="TypeID" Type="Int32" />
        </UpdateParameters>

0 个答案:

没有答案