none
三个DropdownList的联动出现的困扰!!! RRS feed

  • 问题

  •    -- 数据库中的表PropertyTable有三个字段,City(所在城市)、Road(所在路段)、Address(门牌号),分别用三个SQLDateSource三个DropDownList联动对应这三个字段SQLDateSource_City、DropDownList_City和SQLDateSource_Road、DropDownList_Road和 SQLDateSource、DropdownList_Address)。
        --我根据田洪川的视频设置了三个DropdownList的联动,开始运行一切正常。但后来发现一个问题:每次改变了DropdownList_City或DropdownList_Road后,后面的DropdownList都会增加上次显示的项,越来越多。
        --为解决这个问题我用了个蠢办法,设了一个刷新键,隔那么久就刷新一下,很不方便!!
       -- 这个问题该如何解决???请各位不吝赐教!代码很长,只看DropdownList部分就好了!
    -
    ====================具体代码如下:===========================
    <span style="white-space:normal"><pre><%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="PropertyManage.aspx.cs" Inherits="PropertyTable_PropertyManage" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
     <style type="text/css">
      .style2
      {
       height: 31px;
      }
     </style>
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
    
    
    
     <table cellpadding="0" cellspacing="0" class="style1">
      <tr>
       <td align="center" class="style2" 
        style="background-color: #FFFBD6; color: #990000; font-size: large; font-family: 楷体_GB2312; font-style: normal; font-weight: bold;">
        资产信息修改表</td>
       <td class="style2">
        </td>
      </tr>
      <tr>
       <td>
        所在城市:<asp:DropDownList ID="DropDownList_City" runat="server" 
         AutoPostBack="True" DataSourceID="SqlDataSource_City" DataTextField="City" 
         DataValueField="City" AppendDataBoundItems="True" ValidationGroup="Group1">
         <asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem>
        </asp:DropDownList>
        所在路段:<asp:DropDownList ID="DropDownList_Road" runat="server" 
         AutoPostBack="True" DataSourceID="SqlDataSource_Road" DataTextField="Road" 
         DataValueField="Road" AppendDataBoundItems="True" ValidationGroup="Group1">
         <asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem>
        </asp:DropDownList>
        地址:<asp:DropDownList ID="DropDownList_Address" runat="server" 
         AutoPostBack="True" DataSourceID="SqlDataSource_Address" 
         DataTextField="Address" DataValueField="Address" 
         AppendDataBoundItems="True" ValidationGroup="Group1">
         <asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem>
        </asp:DropDownList>
        <asp:Button ID="Button_F5" runat="server" onclick="Button_F5_Click" 
         Text="-刷新-" />
       </td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        <asp:GridView ID="GridView_Search" runat="server" AutoGenerateColumns="False" 
         CellPadding="4" DataSourceID="SqlDataSource_Search" ForeColor="#333333" 
         GridLines="None" AllowSorting="True" DataKeyNames="City,Road,Address">
         <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <Columns>
          <asp:CommandField HeaderText="编辑" ShowDeleteButton="True" ShowEditButton="True">
          <HeaderStyle Width="60px" />
          <ItemStyle Font-Size="Small" Width="60px" />
          </asp:CommandField>
          <asp:BoundField DataField="City" HeaderText="所在城市" ReadOnly="True" 
           SortExpression="City">
          <ControlStyle Font-Size="Small" Width="60px" />
          <FooterStyle HorizontalAlign="Right" />
          <ItemStyle Font-Size="Small" HorizontalAlign="Right" Width="60px" />
          </asp:BoundField>
    <asp:BoundField DataField="Road" HeaderText="所在路段" SortExpression="Road" ReadOnly="True">
          <ControlStyle Font-Size="Small" Width="60px" />
          <HeaderStyle Width="60px" />
          <ItemStyle Font-Size="Small" HorizontalAlign="Right" Width="60px" />
    </asp:BoundField>
    <asp:BoundField DataField="Address" HeaderText="地址" SortExpression="Address" ReadOnly="True">
          <ControlStyle Font-Size="Small" Width="120px" />
          <HeaderStyle Width="120px" />
          <ItemStyle Font-Size="Small" HorizontalAlign="Left" Width="120px" />
    </asp:BoundField>
    <asp:CheckBoxField DataField="PropertyState" HeaderText="是否启用" SortExpression="PropertyState">
          <ControlStyle Font-Size="Small" Width="40px" />
          <HeaderStyle Width="40px" />
          <ItemStyle Font-Size="Small" Width="40px" />
    </asp:CheckBoxField>
          <asp:BoundField DataField="RoomQuantity" HeaderText="间或处" 
           SortExpression="RoomQuantity" >
          <ControlStyle Font-Size="Small" Width="100px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
          <asp:BoundField DataField="Floor" HeaderText="楼层" SortExpression="Floor" >
          <ControlStyle Font-Size="Small" Width="80px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
          <asp:CheckBoxField DataField="NearTheRoad" HeaderText="是否临街" 
           SortExpression="NearTheRoad" ItemStyle-HorizontalAlign="Center">
          <ControlStyle Font-Size="Small" Width="80px" />
    <ItemStyle HorizontalAlign="Center" Font-Size="Small"></ItemStyle>
          </asp:CheckBoxField>
          <asp:BoundField DataField="BuildingArea" HeaderText="建筑面积" 
           SortExpression="BuildingArea" >
          <ControlStyle Font-Size="Small" Width="120px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
          <asp:BoundField DataField="UsingArea" HeaderText="使用面积" 
           SortExpression="UsingArea" >
          <ControlStyle Font-Size="Small" Width="120px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
          <asp:BoundField DataField="ConstructionType" HeaderText="建筑性质" 
           SortExpression="ConstructionType" >
          <ControlStyle Font-Size="Small" Width="120px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
          <asp:BoundField DataField="PropertyType" HeaderText="资产类型" 
           SortExpression="PropertyType" >
          <ControlStyle Font-Size="Small" Width="80px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
          <asp:BoundField DataField="PropertyRemarks" HeaderText="资产备注" 
           SortExpression="PropertyRemarks" >
          <ControlStyle Font-Size="X-Small" Width="120px" />
          <HeaderStyle Width="120px" />
          <ItemStyle Font-Size="X-Small" Width="120px" Wrap="False" />
          </asp:BoundField>
          <asp:BoundField DataField="BelongToCompany" HeaderText="所属分公司" 
           SortExpression="BelongToCompany" >
          <ControlStyle Font-Size="Small" Width="100px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
          <asp:BoundField DataField="SupplyElectricity" HeaderText="电力供应" 
           SortExpression="SupplyElectricity" >
          <ControlStyle Font-Size="Small" Width="60px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
          <asp:BoundField DataField="SupplyWater" HeaderText="水力供应" 
           SortExpression="SupplyWater" >
          <ControlStyle Font-Size="Small" Width="60px" />
          <ItemStyle Font-Size="Small" />
          </asp:BoundField>
         </Columns>
         <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
         <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
         <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
         <EditRowStyle BackColor="#999999" />
         <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
       </td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        <asp:GridView ID="GridView_All" runat="server" AllowPaging="True" 
         AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" 
         DataSourceID="SqlDataSource_All" ForeColor="#333333" GridLines="None" 
         DataKeyNames="City,Road,Address" Visible="False" >
         <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
         <Columns>
          <asp:BoundField DataField="City" HeaderText="City" ReadOnly="True" 
           SortExpression="City">
          </asp:BoundField>
    <asp:BoundField DataField="Road" HeaderText="Road" SortExpression="Road" ReadOnly="True">
    </asp:BoundField>
    <asp:BoundField DataField="Address" HeaderText="Address" SortExpression="Address" ReadOnly="True">
    </asp:BoundField>
    <asp:CheckBoxField DataField="PropertyState" HeaderText="PropertyState" SortExpression="PropertyState">
    </asp:CheckBoxField>
          <asp:BoundField DataField="RoomQuantity" HeaderText="RoomQuantity" 
           SortExpression="RoomQuantity" >
          </asp:BoundField>
          <asp:BoundField DataField="Floor" HeaderText="Floor" SortExpression="Floor" >
          </asp:BoundField>
          <asp:CheckBoxField DataField="NearTheRoad" HeaderText="NearTheRoad" 
           SortExpression="NearTheRoad" ItemStyle-HorizontalAlign="Center">
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
          </asp:CheckBoxField>
          <asp:BoundField DataField="BuildingArea" HeaderText="BuildingArea" 
           SortExpression="BuildingArea">
          </asp:BoundField>
          <asp:BoundField DataField="UsingArea" HeaderText="UsingArea" 
           SortExpression="UsingArea" >
          </asp:BoundField>
          <asp:BoundField DataField="ConstructionType" HeaderText="ConstructionType" 
           SortExpression="ConstructionType" >
          </asp:BoundField>
          <asp:BoundField DataField="PropertyType" HeaderText="PropertyType" 
           SortExpression="PropertyType" >
          </asp:BoundField>
          <asp:BoundField DataField="PropertyRemarks" HeaderText="PropertyRemarks" 
           SortExpression="PropertyRemarks" >
          </asp:BoundField>
          <asp:BoundField DataField="BelongToCompany" HeaderText="BelongToCompany" 
           SortExpression="BelongToCompany" >
          </asp:BoundField>
          <asp:BoundField DataField="SupplyElectricity" HeaderText="SupplyElectricity" 
           SortExpression="SupplyElectricity" >
          </asp:BoundField>
          <asp:BoundField DataField="SupplyWater" HeaderText="SupplyWater" 
           SortExpression="SupplyWater" >
          </asp:BoundField>
         </Columns>
         <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
         <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
         <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
         <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
         <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
       </td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        <asp:SqlDataSource ID="SqlDataSource_Search" runat="server" 
         ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" 
         DeleteCommand="DELETE FROM [PropertyTable] WHERE [City] = @original_City AND [Road] = @original_Road AND [Address] = @original_Address" 
         InsertCommand="INSERT INTO [PropertyTable] ([City], [Road], [Address], [PropertyState], [RoomQuantity], [Floor], [NearTheRoad], [BuildingArea], [UsingArea], [ConstructionType], [PropertyType], [PropertyRemarks], [BelongToCompany], [SupplyElectricity], [SupplyWater]) VALUES (@City, @Road, @Address, @PropertyState, @RoomQuantity, @Floor, @NearTheRoad, @BuildingArea, @UsingArea, @ConstructionType, @PropertyType, @PropertyRemarks, @BelongToCompany, @SupplyElectricity, @SupplyWater)" 
         OldValuesParameterFormatString="original_{0}" 
         SelectCommand="SELECT City, Road, Address, PropertyState, RoomQuantity, Floor, NearTheRoad, BuildingArea, UsingArea, ConstructionType, PropertyType, PropertyRemarks, BelongToCompany, SupplyElectricity, SupplyWater FROM PropertyTable WHERE (ISNULL(@City, N'') = '-1') AND (ISNULL(@Road, N'') = '-1') AND (ISNULL(@Address, N'') = '-1') OR (ISNULL(@City, N'') = '-1') AND (ISNULL(@Address, N'') = '-1') AND (Road = @Road) OR (ISNULL(@Road, N'') = '-1') AND (ISNULL(@Address, N'') = '-1') AND (City = @City) OR (ISNULL(@Address, N'') = '-1') AND (Road = @Road) AND (City = @City) OR (ISNULL(@City, N'') = '-1') AND (ISNULL(@Road, N'') = '-1') AND (Address = @Address) OR (ISNULL(@City, N'') = '-1') AND (Road = @Road) AND (Address = @Address) OR (ISNULL(@Road, N'') = '-1') AND (City = @City) AND (Address = @Address) OR (Road = @Road) AND (City = @City) AND (Address = @Address)" 
         
         
         
         UpdateCommand="UPDATE [PropertyTable] SET [PropertyState] = @PropertyState, [RoomQuantity] = @RoomQuantity, [Floor] = @Floor, [NearTheRoad] = @NearTheRoad, [BuildingArea] = @BuildingArea, [UsingArea] = @UsingArea, [ConstructionType] = @ConstructionType, [PropertyType] = @PropertyType, [PropertyRemarks] = @PropertyRemarks, [BelongToCompany] = @BelongToCompany, [SupplyElectricity] = @SupplyElectricity, [SupplyWater] = @SupplyWater WHERE [City] = @original_City AND [Road] = @original_Road AND [Address] = @original_Address">
         <SelectParameters>
          <asp:ControlParameter ControlID="DropDownList_City" Name="City" 
           PropertyName="SelectedValue" Type="String" DefaultValue="-1" />
          <asp:ControlParameter ControlID="DropDownList_Road" Name="Road" 
           PropertyName="SelectedValue" Type="String" DefaultValue="-1" />
          <asp:ControlParameter ControlID="DropDownList_Address" Name="Address" 
           PropertyName="SelectedValue" Type="String" DefaultValue="-1" />
         </SelectParameters>
         <DeleteParameters>
          <asp:Parameter Name="original_City" Type="String" />
          <asp:Parameter Name="original_Road" Type="String" />
          <asp:Parameter Name="original_Address" Type="String" />
         </DeleteParameters>
         <UpdateParameters>
          <asp:Parameter Name="PropertyState" Type="Boolean" />
          <asp:Parameter Name="RoomQuantity" Type="Int32" />
          <asp:Parameter Name="Floor" Type="Int32" />
          <asp:Parameter Name="NearTheRoad" Type="Boolean" />
          <asp:Parameter Name="BuildingArea" Type="Decimal" />
          <asp:Parameter Name="UsingArea" Type="Decimal" />
          <asp:Parameter Name="ConstructionType" Type="String" />
          <asp:Parameter Name="PropertyType" Type="String" />
          <asp:Parameter Name="PropertyRemarks" Type="String" />
          <asp:Parameter Name="BelongToCompany" Type="String" />
          <asp:Parameter Name="SupplyElectricity" Type="String" />
          <asp:Parameter Name="SupplyWater" Type="String" />
          <asp:Parameter Name="original_City" Type="String" />
          <asp:Parameter Name="original_Road" Type="String" />
          <asp:Parameter Name="original_Address" Type="String" />
         </UpdateParameters>
         <InsertParameters>
          <asp:Parameter Name="City" Type="String" />
          <asp:Parameter Name="Road" Type="String" />
          <asp:Parameter Name="Address" Type="String" />
          <asp:Parameter Name="PropertyState" Type="Boolean" />
          <asp:Parameter Name="RoomQuantity" Type="Int32" />
          <asp:Parameter Name="Floor" Type="Int32" />
          <asp:Parameter Name="NearTheRoad" Type="Boolean" />
          <asp:Parameter Name="BuildingArea" Type="Decimal" />
          <asp:Parameter Name="UsingArea" Type="Decimal" />
          <asp:Parameter Name="ConstructionType" Type="String" />
          <asp:Parameter Name="PropertyType" Type="String" />
          <asp:Parameter Name="PropertyRemarks" Type="String" />
          <asp:Parameter Name="BelongToCompany" Type="String" />
          <asp:Parameter Name="SupplyElectricity" Type="String" />
          <asp:Parameter Name="SupplyWater" Type="String" />
         </InsertParameters>
        </asp:SqlDataSource>
       </td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        <asp:SqlDataSource ID="SqlDataSource_All" runat="server" 
         ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" 
         DeleteCommand="DELETE FROM [PropertyTable] WHERE [City] = @original_City AND [Road] = @original_Road AND [Address] = @original_Address" 
         InsertCommand="INSERT INTO [PropertyTable] ([City], [Road], [Address], [PropertyState], [RoomQuantity], [Floor], [NearTheRoad], [BuildingArea], [UsingArea], [ConstructionType], [PropertyType], [PropertyRemarks], [BelongToCompany], [SupplyElectricity], [SupplyWater]) VALUES (@City, @Road, @Address, @PropertyState, @RoomQuantity, @Floor, @NearTheRoad, @BuildingArea, @UsingArea, @ConstructionType, @PropertyType, @PropertyRemarks, @BelongToCompany, @SupplyElectricity, @SupplyWater)" 
         OldValuesParameterFormatString="original_{0}" 
         SelectCommand="SELECT [City], [Road], [Address], [PropertyState], [RoomQuantity], [Floor], [NearTheRoad], [BuildingArea], [UsingArea], [ConstructionType], [PropertyType], [PropertyRemarks], [BelongToCompany], [SupplyElectricity], [SupplyWater] FROM [PropertyTable]" 
         
         
         
         
         
         UpdateCommand="UPDATE [PropertyTable] SET [PropertyState] = @PropertyState, [RoomQuantity] = @RoomQuantity, [Floor] = @Floor, [NearTheRoad] = @NearTheRoad, [BuildingArea] = @BuildingArea, [UsingArea] = @UsingArea, [ConstructionType] = @ConstructionType, [PropertyType] = @PropertyType, [PropertyRemarks] = @PropertyRemarks, [BelongToCompany] = @BelongToCompany, [SupplyElectricity] = @SupplyElectricity, [SupplyWater] = @SupplyWater WHERE [City] = @original_City AND [Road] = @original_Road AND [Address] = @original_Address">
         <DeleteParameters>
          <asp:Parameter Name="original_City" Type="String" />
          <asp:Parameter Name="original_Road" Type="String" />
          <asp:Parameter Name="original_Address" Type="String" />
         </DeleteParameters>
         <UpdateParameters>
          <asp:Parameter Name="PropertyState" Type="Boolean" />
          <asp:Parameter Name="RoomQuantity" Type="Int32" />
          <asp:Parameter Name="Floor" Type="Int32" />
          <asp:Parameter Name="NearTheRoad" Type="Boolean" />
          <asp:Parameter Name="BuildingArea" Type="Decimal" />
          <asp:Parameter Name="UsingArea" Type="Decimal" />
          <asp:Parameter Name="ConstructionType" Type="String" />
          <asp:Parameter Name="PropertyType" Type="String" />
          <asp:Parameter Name="PropertyRemarks" Type="String" />
          <asp:Parameter Name="BelongToCompany" Type="String" />
          <asp:Parameter Name="SupplyElectricity" Type="String" />
          <asp:Parameter Name="SupplyWater" Type="String" />
          <asp:Parameter Name="original_City" Type="String" />
          <asp:Parameter Name="original_Road" Type="String" />
          <asp:Parameter Name="original_Address" Type="String" />
         </UpdateParameters>
         <InsertParameters>
          <asp:Parameter Name="City" Type="String" />
          <asp:Parameter Name="Road" Type="String" />
          <asp:Parameter Name="Address" Type="String" />
          <asp:Parameter Name="PropertyState" Type="Boolean" />
          <asp:Parameter Name="RoomQuantity" Type="Int32" />
          <asp:Parameter Name="Floor" Type="Int32" />
          <asp:Parameter Name="NearTheRoad" Type="Boolean" />
          <asp:Parameter Name="BuildingArea" Type="Decimal" />
          <asp:Parameter Name="UsingArea" Type="Decimal" />
          <asp:Parameter Name="ConstructionType" Type="String" />
          <asp:Parameter Name="PropertyType" Type="String" />
          <asp:Parameter Name="PropertyRemarks" Type="String" />
          <asp:Parameter Name="BelongToCompany" Type="String" />
          <asp:Parameter Name="SupplyElectricity" Type="String" />
          <asp:Parameter Name="SupplyWater" Type="String" />
         </InsertParameters>
        </asp:SqlDataSource>
       </td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        <asp:SqlDataSource ID="SqlDataSource_City" runat="server" 
         ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" 
         SelectCommand="SELECT DISTINCT [City] FROM [PropertyTable]">
        </asp:SqlDataSource>
       </td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        <asp:SqlDataSource ID="SqlDataSource_Road" runat="server" 
         ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" 
         
         SelectCommand="SELECT DISTINCT [City], [Road] FROM [PropertyTable] WHERE ([City] = @City)" 
         ProviderName="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString.ProviderName %>">
         <SelectParameters>
          <asp:ControlParameter ControlID="DropDownList_City" Name="City" 
           PropertyName="SelectedValue" Type="String" ConvertEmptyStringToNull="False" />
         </SelectParameters>
        </asp:SqlDataSource>
       </td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        <asp:SqlDataSource ID="SqlDataSource_Address" runat="server" 
         ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" 
         
         SelectCommand="SELECT DISTINCT [Address] FROM [PropertyTable] WHERE (([City] = @City) AND ([Road] = @Road))">
         <SelectParameters>
          <asp:ControlParameter ControlID="DropDownList_City" DefaultValue="-1" 
           Name="City" PropertyName="SelectedValue" Type="String" ConvertEmptyStringToNull="False" />
          <asp:ControlParameter ControlID="DropDownList_Road" DefaultValue="-1" 
           Name="Road" PropertyName="SelectedValue" Type="String" />
         </SelectParameters>
        </asp:SqlDataSource>
       </td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        &nbsp;</td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        &nbsp;</td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        &nbsp;</td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        &nbsp;</td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        &nbsp;</td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        &nbsp;</td>
       <td>
        &nbsp;</td>
      </tr>
      <tr>
       <td>
        &nbsp;</td>
       <td>
        &nbsp;</td>
      </tr>
     </table>
    
    
    
    </asp:Content>
    <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    </asp:Content>
    
    



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

答案

  • (ISNULL(@City, N'') = '-1') AND (ISNULL(@Road, N'') = '-1'
    =====================================================
     改成 
    (ISNULL(@City, N'') =N '未选择') AND (ISNULL(@Road, N'') = N'未选择'

    还是-------------------------------------
     
    (ISNULL(@City, N'') = '未选择') AND (ISNULL(@Road, N'') = '未选择'

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

     

    我想您的数据库Collations应该是简体中文,请先以后者试试看,不行的话再换前者


    Shadowと愉快なコード達
    2011年8月12日 13:48

全部回复

  • 把Dropdownlist的AppendDataBoundItems設為false即可。

    或是刪除你設定AppendDataBoundItems="true"的部分也可以達到相同效果,因為預設AppendDataBoundItems為false。

     

    ListControl.AppendDataBoundItems 屬性

     


    以上說明若有錯誤請指教,謝謝。
    http://www.dotblogs.com.tw/terrychuang/

    2011年8月12日 10:10
  •     谢谢您的及时回复!把Dropdownlist的AppendDataBoundItems設為false即可当然可以解决这个问题,但这样做会引起一个新的问题!

        我的DropdownList都设置了“未选择”这个值,为了使用“未选择”这个值,我只能把AppendDataBoundItems属性设置为True。您看我说的有没有错!?

    所在城市:<asp:DropDownList ID="DropDownList_City" runat="server" 
              AutoPostBack="True" DataSourceID="SqlDataSource_City" DataTextField="City" 
              DataValueField="City" AppendDataBoundItems="True" ValidationGroup="Group1">
              <strong><asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem></strong>
            </asp:DropDownList>
            所在路段:<asp:DropDownList ID="DropDownList_Road" runat="server" 
              AutoPostBack="True" DataSourceID="SqlDataSource_Road" DataTextField="Road" 
              DataValueField="Road" AppendDataBoundItems="True" ValidationGroup="Group1">
              <strong><asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem>
            </asp:DropDownList></strong><br/>
            地址:<asp:DropDownList ID="DropDownList_Address" runat="server" 
              AutoPostBack="True" DataSourceID="SqlDataSource_Address" 
              DataTextField="Address" DataValueField="Address" 
              AppendDataBoundItems="True" ValidationGroup="Group1">
              <strong><asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem>
            </asp:DropDownList></strong>
    



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

  • 1.拿掉AppendDataBoundItems="true"
    所在城市:<asp:DropDownList ID="DropDownList_City" runat="server" AutoPostBack="True"
         DataSourceID="SqlDataSource_City" DataTextField="City" DataValueField="City"
         ValidationGroup="Group1">
        </asp:DropDownList>
    
        所在路段:<asp:DropDownList ID="DropDownList_Road" runat="server" AutoPostBack="True"
         DataSourceID="SqlDataSource_Road" DataTextField="Road" DataValueField="Road"
          ValidationGroup="Group1">
        </asp:DropDownList>
    
        地址:<asp:DropDownList ID="DropDownList_Address" runat="server" AutoPostBack="True"
         DataSourceID="SqlDataSource_Address" DataTextField="Address" DataValueField="Address"
         ValidationGroup="Group1">
        </asp:DropDownList>
    

     

    2.更改SqlDataSource的SeleceCommand

     

        <asp:SqlDataSource ID="SqlDataSource_City" runat="server" ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>"
         SelectCommand="Select N'未选择' AS City Union All SELECT DISTINCT [City] FROM [PropertyTable]"></asp:SqlDataSource>
    
          <asp:SqlDataSource ID="SqlDataSource_Road" runat="server" ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>"
         SelectCommand="Select N'未选择' AS Road Union All SELECT DISTINCT [Road] FROM [PropertyTable] WHERE ([City] = @City)"
         ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>">
    
         <SelectParameters>
          <asp:ControlParameter ControlID="DropDownList_City" Name="City" PropertyName="SelectedValue"
           Type="String" ConvertEmptyStringToNull="False" />
         </SelectParameters>
        </asp:SqlDataSource>
    
          <asp:SqlDataSource ID="SqlDataSource_Address" runat="server" ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>"
         SelectCommand="Select N'未选择' AS Address Union All SELECT DISTINCT [Address] FROM [PropertyTable] WHERE (([City] = @City) AND ([Road] = @Road))">
         <SelectParameters>
          <asp:ControlParameter ControlID="DropDownList_City" DefaultValue="-1" Name="City"
           PropertyName="SelectedValue" Type="String" ConvertEmptyStringToNull="False" />
          <asp:ControlParameter ControlID="DropDownList_Road" DefaultValue="-1" Name="Road"
           PropertyName="SelectedValue" Type="String" />
         </SelectParameters>
        </asp:SqlDataSource>
       
    
    

    Shadowと愉快なコード達

    2011年8月12日 11:55
  • 非常感谢您的及时回复!我重新做了个简单的三级联动,暂时没出现前面的错误!

     

    我想再多问两个问题:

    问题1:SelectCommand="Select N'未选择' AS Address Union All SELECT DISTINCT [Address] FROM [PropertyTable] WHERE (([City] = @City) AND ([Road] = @Road))"

        这一句在VS2008的SqlDataSource中的Select语句中是怎么写的,N'未选择' 是VS2008给添加上去的,求在下面这个界面中的原始写法。

    问题2: 我原来设置了如果是没选择的话,对应的Sql语句中空值是这样表示的:

     (ISNULL(@City, N'') = '-1') AND (ISNULL(@Road, N'') = '-1'

    如果我用了您的方法后,我原来的SqlDataSource_Search要做哪些修改呢???

    ========SqldataSource_Search的主要内容=========


    <asp:SqlDataSource ID="SqlDataSource_Search" runat="server" 
       ConnectionString="<%$ ConnectionStrings:长铁物业公司资产数据库ConnectionString %>" 
       DeleteCommand="DELETE FROM [PropertyTable] WHERE [City] = @original_City AND [Road] = @original_Road AND [Address] = @original_Address" 
       InsertCommand="INSERT INTO [PropertyTable] ([City], [Road], [Address], [PropertyState], [RoomQuantity], [Floor], [NearTheRoad], [BuildingArea], [UsingArea], [ConstructionType], [PropertyType], [PropertyRemarks], [BelongToCompany], [SupplyElectricity], [SupplyWater]) VALUES (@City, @Road, @Address, @PropertyState, @RoomQuantity, @Floor, @NearTheRoad, @BuildingArea, @UsingArea, @ConstructionType, @PropertyType, @PropertyRemarks, @BelongToCompany, @SupplyElectricity, @SupplyWater)" 
       OldValuesParameterFormatString="original_{0}" 
       SelectCommand="SELECT City, Road, Address, PropertyState, RoomQuantity, Floor, NearTheRoad, BuildingArea, UsingArea, ConstructionType, PropertyType, PropertyRemarks, BelongToCompany, SupplyElectricity, SupplyWater FROM PropertyTable WHERE (ISNULL(@City, N'') = '-1') AND (ISNULL(@Road, N'') = '-1') AND (ISNULL(@Address, N'') = '-1') OR (ISNULL(@City, N'') = '-1') AND (ISNULL(@Address, N'') = '-1') AND (Road = @Road) OR (ISNULL(@Road, N'') = '-1') AND (ISNULL(@Address, N'') = '-1') AND (City = @City) OR (ISNULL(@Address, N'') = '-1') AND (Road = @Road) AND (City = @City) OR (ISNULL(@City, N'') = '-1') AND (ISNULL(@Road, N'') = '-1') AND (Address = @Address) OR (ISNULL(@City, N'') = '-1') AND (Road = @Road) AND (Address = @Address) OR (ISNULL(@Road, N'') = '-1') AND (City = @City) AND (Address = @Address) OR (Road = @Road) AND (City = @City) AND (Address = @Address)" 
       
       
       
       UpdateCommand="UPDATE [PropertyTable] SET [PropertyState] = @PropertyState, [RoomQuantity] = @RoomQuantity, [Floor] = @Floor, [NearTheRoad] = @NearTheRoad, [BuildingArea] = @BuildingArea, [UsingArea] = @UsingArea, [ConstructionType] = @ConstructionType, [PropertyType] = @PropertyType, [PropertyRemarks] = @PropertyRemarks, [BelongToCompany] = @BelongToCompany, [SupplyElectricity] = @SupplyElectricity, [SupplyWater] = @SupplyWater WHERE [City] = @original_City AND [Road] = @original_Road AND [Address] = @original_Address">
    

    谢谢大家的帮助!!!


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

  • 1..在那个界面中自己写代码上去或在.aspx中自己改写SelectCommand

     

    2.把所有的 '-1' 改为

    N'未选择'
    

    Shadowと愉快なコード達
    2011年8月12日 13:10
  • (ISNULL(@City, N'') = '-1') AND (ISNULL(@Road, N'') = '-1'
    =====================================================
      改成 
    (ISNULL(@City, N'') =N '未选择') AND (ISNULL(@Road, N'') = N'未选择'

    还是-------------------------------------
      
    (ISNULL(@City, N'') = '未选择') AND (ISNULL(@Road, N'') = '未选择'

    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!
    2011年8月12日 13:26
  • (ISNULL(@City, N'') = '-1') AND (ISNULL(@Road, N'') = '-1'
    =====================================================
     改成 
    (ISNULL(@City, N'') =N '未选择') AND (ISNULL(@Road, N'') = N'未选择'

    还是-------------------------------------
     
    (ISNULL(@City, N'') = '未选择') AND (ISNULL(@Road, N'') = '未选择'

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

     

    我想您的数据库Collations应该是简体中文,请先以后者试试看,不行的话再换前者


    Shadowと愉快なコード達
    2011年8月12日 13:48

  •     谢谢您的及时回复!把Dropdownlist的AppendDataBoundItems設為false即可当然可以解决这个问题,但这样做会引起一个新的问题!

        我的DropdownList都设置了“未选择”这个值,为了使用“未选择”这个值,我只能把AppendDataBoundItems属性设置为True。您看我说的有没有错!?

     

    所在城市:<asp:DropDownList ID="DropDownList_City" runat="server" 
       AutoPostBack="True" DataSourceID="SqlDataSource_City" DataTextField="City" 
       DataValueField="City" AppendDataBoundItems="True" ValidationGroup="Group1">
       <strong><asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem></strong>
      </asp:DropDownList>
      所在路段:<asp:DropDownList ID="DropDownList_Road" runat="server" 
       AutoPostBack="True" DataSourceID="SqlDataSource_Road" DataTextField="Road" 
       DataValueField="Road" AppendDataBoundItems="True" ValidationGroup="Group1">
       <strong><asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem>
      </asp:DropDownList></strong><br/>
      地址:<asp:DropDownList ID="DropDownList_Address" runat="server" 
       AutoPostBack="True" DataSourceID="SqlDataSource_Address" 
       DataTextField="Address" DataValueField="Address" 
       AppendDataBoundItems="True" ValidationGroup="Group1">
       <strong><asp:ListItem Selected="True" Value="-1">未选择</asp:ListItem>
      </asp:DropDownList></strong>
    


     


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

    1. AppendDataBoundItems設為false。

    2.加入下列程式碼:

     

    ListItem li = new ListItem("未选择", "-1");
    li.Selected = true; DropDownList_City.Items.Insert(0, li); DropDownList_Road.Items.Insert(0,li); DropDownList_Address.Items.Insert(0, li);


     


    以上說明若有錯誤請指教,謝謝。
    http://www.dotblogs.com.tw/terrychuang/
    2011年8月12日 14:10
  • 2.加入下列程式碼:

    ListItem li = new ListItem("未??", "-1");
    
     

    To Terry大:

    建议您可以使用繁简转换工具:
    http://tdc.putonghuaonline.com/tools3.html

    这边的童鞋们会比较好阅读


    Shadowと愉快なコード達
    2011年8月12日 14:25
  • To Shadow:

    感謝,我了解了~


    以上說明若有錯誤請指教,謝謝。
    http://www.dotblogs.com.tw/terrychuang/
    2011年8月12日 14:30
  • 明天试试!!!3Q!!!
    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!
    2011年8月12日 14:38
  • 两位的方法都能解决问题,所不同的是一个是在前台代码中解决,另一个是在后台代码中解决!非常感谢!!!
    C# 菜鸟中的雏鸟!提的问题也许很幼稚,但我是认真的。希望看在党国的面子上拉兄弟一把!
    2011年8月14日 5:53