asp FormView EditItemTemplate绑定值

时间:2016-08-11 16:32:08

标签: asp.net data-binding drop-down-menu

因此我无法从FormViewEditItemTemplate

绑定下拉列表

我创建了一个asp:SqlDataSource,设置了UpdateCommand,据说绑定了id_enabled值,虽然它没有工作

当我按下编辑按钮时,它会崩溃并发出以下错误

DataBinding:' System.Data.DataRowView'不包含名称为' id_enabled'

的媒体资源
<%@ Page 
    Title="" 
    Language="C#" 
    MasterPageFile="~/AdminPanel.Master" 
    AutoEventWireup="true" 
    CodeBehind="PassportDetail.aspx.cs" 
    Inherits="TipTourAdminPanel.PassportDetail" %>

<asp:Content 
    ID="Content1" 
    ContentPlaceHolderID="head" 
    runat="server">
</asp:Content>

<asp:Content 
    ID="Content2" 
    ContentPlaceHolderID="ContentPlaceHolder1" 
    runat="server">

    <asp:SqlDataSource 
        ID="SqlDataSource_rewardDetail" .  


        runat="server" 
        ConnectionString="<%$ ConnectionStrings:Tip-Tour %>"  

        SelectCommand= "SELECT 
                            tt_passport.id_passport,
                            tt_passport.id_tour, 
                            tt_passport.description AS passport_description,
                            tt_passport.id_passport_requirement,
                            tt_passport_requirement.description AS passport_requirements,
                            tt_tour.title AS tour_title,
                            tt_tour.body AS tour_description,
                            tt_passport.enabled             

                        FROM tt_passport

                            JOIN tt_passport_requirement
                                ON tt_passport_requirement.id_passport_requirement = tt_passport.id_passport_requirement

                            JOIN tt_tour
                                ON tt_tour.id_tour = tt_passport.id_tour

                        WHERE tt_passport.id_passport = @id_passport"

        UpdateCommand= "UPDATE tt_passport 
                        SET 
                            tt_passport.description = @passport_description,
                            tt_passport.id_passport_requirement = @id_passport_requirement,
                            tt_passport.enabled = @id_enabled

                        WHERE tt_passport.id_passport = @id_passport"


        DeleteCommand= "Delete FROM tt_passport 
                        WHERE tt_passport.id_passport = @id_passport">

        <SelectParameters>
            <asp:QueryStringParameter 
                DefaultValue="0" 
                Name="id_passport" 
                QueryStringField="id_passport" />
        </SelectParameters>

        <UpdateParameters>
            <asp:Parameter Name="passport_description" />
            <asp:Parameter Name="id_passport_requirement" />
            <asp:Parameter Name="id_passport"/>
            <asp:Parameter Name="id_enabled"/>
        </UpdateParameters>

    </asp:SqlDataSource>

    <asp:SqlDataSource 
        ID="sql_enabled_ddl" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:Tip-Tour %>"  

        SelectCommand =";With passport_enabled AS
                        (
                            Select 1 as id_enabled, 'true' AS description                           
                            UNION                       
                            Select 0 as id_enabled, 'false' AS description
                        )
                        SELECT id_enabled, description FROM passport_enabled">

    </asp:SqlDataSource>

    <asp:SqlDataSource 
        ID="SqlDataSource_rewardRequirements" 
        runat="server" 
        ConnectionString="<%$ ConnectionStrings:Tip-Tour %>"  

        SelectCommand= "SELECT 
                            id_passport_requirement, 
                            description 
                        FROM tt_passport_requirement">

    </asp:SqlDataSource>


    <div class="textHeader">Passport:</div>

    <asp:FormView 
        ID="FormView1" 
        runat="server" 
        DataSourceID="SqlDataSource_rewardDetail" 
        DataKeyNames="id_passport">

        <EditItemTemplate>
            <table id="tableForm">
                <tr>
                    <th>id_passport:</th>
                    <td>
                        <asp:Label 
                            Text='<%# Eval("id_passport") %>' 
                            runat="server" 
                            ID="id_passportLabel1" />
                    </td>
                </tr>
                <tr>
                    <th>passport_description:</th>
                    <td>
                        <asp:TextBox 
                            Text='<%# Bind("passport_description") %>' 
                            runat="server" 
                            ID="passport_descriptionTextBox"
                            TextMode="MultiLine" 
                            Rows="10"/>
                    </td>
                </tr>

                <tr>
                    <th>passport_requirements:</th>
                    <td>                
                        <asp:DropDownList
                            ID="DropDownList1"
                            runat="server"
                            DataSourceID="SqlDataSource_rewardRequirements"
                            DataTextField="description"
                            DataValueField="id_passport_requirement" 
                            SelectedValue='<%# Bind("id_passport_requirement") %>' 
                            Width="87%">
                        </asp:DropDownList>             
                    </td>
                </tr>
                <tr>
                    <th>enabled:</th>
                    <td>                
                        <asp:DropDownList
                            ID="DropDownList2"
                            runat="server"
                            DataSourceID="sql_enabled_ddl"
                            DataTextField="description"
                            DataValueField="id_enabled"
                            SelectedValue='<%# Bind("enabled") %>' 
                            Width="87%">
                        </asp:DropDownList>             
                    </td>
                </tr>


            </table>

            <br />

            <asp:LinkButton 
                runat="server" 
                Text="Update" 
                CommandName="Update" 
                ID="UpdateButton" 
                CausesValidation="True" />

            &nbsp;

            <asp:LinkButton 
                runat="server" 
                Text="Cancel" 
                CommandName="Cancel" 
                ID="UpdateCancelButton" 
                CausesValidation="False" />
        </EditItemTemplate>



    </asp:FormView>


</asp:Content>

0 个答案:

没有答案