none
有没有办法像后台的try catch finaly一样把前台代码的错误页忽略掉的方法呢? RRS feed

  • 问题

  •     以下是我在FormView中做的一个联动DropDownList,第一个是表示“城市”,第二个表示“街道”,可是在FormView会出现“

    Eval()、XPath() 和 Bind() 这类数据绑定方法只能在数据绑定控件的上下文中使用

    ”的提示。

        我想干脆象后台做try catch finaly那样也来一个,把错误忽略掉,不知道有什么办法可以把前台的错误忽略掉?

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Form3.aspx.cs" Inherits="TRY_GridViewToDetailsView_Form3" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        
            <asp:FormView ID="FormView1" runat="server" DataKeyNames="CID" 
                DataSourceID="SqlDataSource1">
                <EditItemTemplate>
                    CID:
                    <asp:Label ID="CIDLabel1" runat="server" Text='<%# Eval("CID") %>' />
                    <br />
                    City:
                    <asp:DropDownList ID="DropDownList_City" runat="server" AutoPostBack="True" 
                        DataSourceID="SqlDataSource_City" DataTextField="City" DataValueField="City" 
                        SelectedValue='<%# Bind("City") %>'>
                    </asp:DropDownList>
                    <br />
                    Road:
                    <asp:DropDownList ID="DropDownList_Road" runat="server" AutoPostBack="True" 
                        DataSourceID="SqlDataSource_Road" DataTextField="Road" DataValueField="Road" 
                        SelectedValue='<%# Bind("Road") %>'>
                    </asp:DropDownList>
                    <asp:SqlDataSource ID="SqlDataSource_City" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" 
                        SelectCommand="SELECT distinct [City] FROM [ContractTable]">
                    </asp:SqlDataSource>
                    <asp:SqlDataSource ID="SqlDataSource_Road" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" SelectCommand="SELECT distinct [Road] FROM [ContractTable] where City=@city
    ">
                        <SelectParameters>
                            <asp:ControlParameter ControlID="DropDownList_City" Name="city" 
                                PropertyName="SelectedValue" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                    <br />
                    <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
                        CommandName="Update" Text="更新" />
                    &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
                        CausesValidation="False" CommandName="Cancel" Text="取消" />
                </EditItemTemplate>
                <InsertItemTemplate>
                    City:
                    <asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
                    <br />
                    Road:
                    <asp:TextBox ID="RoadTextBox" runat="server" Text='<%# Bind("Road") %>' />
                    <br />
                    <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
                        CommandName="Insert" Text="插入" />
                    &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
                        CausesValidation="False" CommandName="Cancel" Text="取消" />
                </InsertItemTemplate>
                <ItemTemplate>
                    CID:
                    <asp:Label ID="CIDLabel" runat="server" Text='<%# Eval("CID") %>' />
                    <br />
                    City:
                    <asp:Label ID="CityLabel" runat="server" Text='<%# Bind("City") %>' />
                    <br />
                    Road:
                    <asp:Label ID="RoadLabel" runat="server" Text='<%# Bind("Road") %>' />
                    <br />
                    <asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text="编辑" />
                    &nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" 
                        CommandName="Delete" Text="删除" />
                    &nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" 
                        CommandName="New" Text="新建" />
                </ItemTemplate>
            </asp:FormView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" 
                DeleteCommand="DELETE FROM [ContractTable] WHERE [CID] = @CID" 
                InsertCommand="INSERT INTO [ContractTable] ([City], [Road]) VALUES (@City, @Road)" 
                SelectCommand="SELECT [CID], [City], [Road] FROM [ContractTable]" 
                UpdateCommand="UPDATE [ContractTable] SET [City] = @City, [Road] = @Road WHERE [CID] = @CID">
                <DeleteParameters>
                    <asp:Parameter Name="CID" Type="Int32" />
                </DeleteParameters>
                <UpdateParameters>
                    <asp:Parameter Name="City" Type="String" />
                    <asp:Parameter Name="Road" Type="String" />
                    <asp:Parameter Name="CID" Type="Int32" />
                </UpdateParameters>
                <InsertParameters>
                    <asp:Parameter Name="City" Type="String" />
                    <asp:Parameter Name="Road" Type="String" />
                </InsertParameters>
            </asp:SqlDataSource>
        
        </div>
        </form>
    </body>
    </html>
    


    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!

    2013年5月9日 9:08

答案

全部回复