菜鸟为工作求助
要求是这样的:2个dropDownlist和一个texbox,一个按钮,一个gridview
选择第一个dropDownlist比如区域,然后第二个dropDownlist就根据第一个显示可选择的选项比如说区域内的省份,再在textbox里搜索比如说城镇,点击按钮,把结果显示在gridview
我用datasource做的,但总找不到思路
希望个位高手能给一个例子,不胜感激!
环境为vs2005 c#和sql2005

解决方案 »

  1.   

    关于两个dropdownlist,可以看我在帖子《asp.net dropdownlist 联动 问题》贴出的代码。
      

  2.   

    关于条件查询,可以google:http://www.google.cn/search?q=scott+mitchell+SelectParameters&rls=com.microsoft:*:IE-SearchBox&ie=UTF-8&oe=UTF-8&sourceid=ie7&rlz=1I7GGIJ
      

  3.   

    7楼大哥给的代码是利用ajax的?屌,再去下一个。。愕然发现这个插件都么
      

  4.   

    看看你什么需求,如果要求不高,用asp.nt ajax UpdatePanel模式很容易实现
    这个方式应该能够满足你的要求,但是要装个asp.net ajax组件
      

  5.   

    通过dropdownlist联动实现.再根据条件传值到存储过程或SLQ语句实现数据绑定
    参考
    http://www.cnblogs.com/battler/archive/2005/07/06/97862.html
    http://www.cnblogs.com/sunyong/archive/2006/08/16/478323.aspx
      

  6.   

    算了,我放上一开始我做的代码吧。。让高手来帮我改改<%@ Page Language="C#" AutoEventWireup="true" CodeFile="search.aspx.cs" Inherits="Default4" %><%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        Namespace="System.Web.UI" TagPrefix="asp" %>
    <!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>xx查询</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
          <div align="center">
              <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testcon %>"
                  SelectCommand="select distinct fgs from docddw"></asp:SqlDataSource>
              <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:testcon %>"
                  SelectCommand="select distinct sf from docddw where fgs=@sf ">
                  <SelectParameters>
                      <asp:ControlParameter ControlID="fgs" Name="sf" PropertyName="SelectedValue" />
                  </SelectParameters>
              </asp:SqlDataSource>
              <asp:SqlDataSource ID="SqlDataSource3" runat="server"></asp:SqlDataSource>
              &nbsp;<br />
              &nbsp;<table width="800" border="0">
              <tr>
                <th scope="col" style="height: 24px">选择分公司            :</th>
                <th scope="col" style="height: 24px"><asp:DropDownList ID="fgs" runat="server" OnSelectedIndexChanged="fgs_SelectedIndexChanged" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="fgs" DataValueField="fgs">
                <asp:ListItem Value="000">--请选择--</asp:ListItem>      
                </asp:DropDownList>
                </th>
                
                <th scope="col" style="height: 24px">选择省份:</th>
                <th scope="col" style="height: 24px">
                    &nbsp;<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
                        Style="position: relative">
                    </asp:DropDownList></th>
         </tr>
              <tr>
                <th scope="row">输入要查询的xx:</th>
                <td colspan="3"><asp:TextBox ID="name" runat="server" /></td>
              </tr>
              <tr>
                <th colspan="4" scope="row"><asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="查询" /></th>
              </tr>
              <tr>
                <th scope="row">&nbsp;</th>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
                <td>&nbsp;</td>
              </tr>
              <tr>
                <th scope="row" colspan="4"> <asp:GridView ID="GridView1" runat="server" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" CellPadding="4" ForeColor="#333333" GridLines="None" Height="391px" Width="741px" AutoGenerateColumns="False">        
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                    <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></th>
              </tr>
            </table>
              &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
              &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
              &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
             
                                   
                                   
                                   
                                   
              </div>
            <div align="center"><br />
      &nbsp; &nbsp;
            </div>
           
        </div>
        </form>
    </body>
    </html>
      

  7.   

    呃,你QQ呢?
    还有,上面的代码我在配置数据源时测试能成功,但一运行这个页面就会在第二个DDL里面出现system.data.row之类的,而没有绑定的数据
      

  8.   

    oh yeah,原来我上面的思路是可以的。。虽然要刷新,但好歹成功了。。=下结账哈。。谢谢各位~~