何在FormView控件的EditItemTemplate中绑定

何在FormView控件的EditItemTemplate中绑定

本文介绍了如何在FormView控件的EditItemTemplate中绑定dropdownlist?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将Visual Web Developer Express 2010与ASP.NET 4.0一起使用。

Using Visual Web Developer Express 2010 with ASP.NET 4.0.

我有一个FormView,我想从数据库中设置一个默认值。我无法将其绑定到数据库中的值。我的FormView看起来像这样:

I have a FormView and I want to set a default value from the database. I can't get it to bind to the value in the database. My FormView looks like this:

<asp:FormView
ID="frmOrderDetails"
DataSourceID="sdsFormOrderDetails"
runat="server"
DataKeyNames="orderId">

<EditItemTemplate>
    <h3>Edit Order Details</h3>

    <asp:Label ID="lblStrategy" Text="Strategy:" AssociatedControlID="ddlStrategies" runat="server"  />
    <asp:DropDownList SelectedValue='<%# Bind("strategyId") %>'
    ID="ddlStrategies"
    runat="server"
    DataTextField="strategy"
    DataValueField="strategyId"
    DataSourceID="sdsStrategies"
     />

    <asp:LinkButton
    id="lnkUpdate"
    Text="Update Order"
    CommandName="Update"
    Runat="server" />
    |
    <asp:LinkButton
    id="lnkCancel"
    Text="Cancel"
    CommandName="Cancel"
    Runat="server" />

</EditItemTemplate>
</asp:FormView>

<asp:SqlDataSource ID="sdsFormOrderDetails" runat="server"
    ConnectionString="<%$ ConnectionStrings:LocalSQLServer %>"
    ProviderName="<%$ ConnectionStrings:LocalSQLServer.ProviderName %>"
    SelectCommand="usp_GetOrderDetails" SelectCommandType="StoredProcedure"
    UpdateCommand="usp_UpdateOrder" UpdateCommandType="StoredProcedure">
    <SelectParameters>
        <asp:ControlParameter Name="orderId" ControlID="grdOrders" PropertyName="SelectedDataKey.Value" />
    </SelectParameters>
    <UpdateParameters>
        <asp:ControlParameter Name="orderId" ControlID="grdOrders" />
    </UpdateParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="sdsStrategies" runat="server"
    ConnectionString="<%$ ConnectionStrings:LocalSQLServer %>"
    ProviderName="<%$ ConnectionStrings:LocalSQLServer.ProviderName %>"
    SelectCommand="usp_GetStrategiesDropDown">
</asp:SqlDataSource>

当我单击FormView控件上的编辑按钮时,EditItemTemplate甚至没有加载。

The EditItemTemplate does not even load when I click the edit button on my FormView control, but I don't get an error message either.

推荐答案

您需要执行以下操作来绑定 DropDownList EditItemTemplate

You need to do the following to bind a DropDownList to the EditItemTemplate:


  1. 添加 DropDownList 及其 DataSource EditItemTemplate

  2. 设置 DropDownList 参数:

DataSourceID="SqlDataSourceDropDownlist" SelectedValue=<%# Bind("ValueToBind") %>
DataTextField="ValueToDisplay" DataValueField="ValueToBind"


  • 设置 ListView / FormView数据源< UdateParameters> ;:< asp:Parameter Name = RankID Type = Int32 />

    这篇关于如何在FormView控件的EditItemTemplate中绑定dropdownlist?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 08-16 01:14