1、SqlDataSource1.Select()到底何解,如何使用?最好举个简单的例子2、还有我新建了一个GridView,查询的时候使用了条件过滤,我如何放入条件,得到我想要的结果,代码如下:
        <asp:GridView ID="GridView1" runat="server" DataKeyNames="ACC1,ID" DataSourceID="SqlDataSource1"
           >
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowSelectButton="True" />
                <asp:BoundField DataField="ACC1" HeaderText="ACC1" ReadOnly="True" SortExpression="ACC1" />
                <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
                  ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>" SelectCommand='SELECT "ACC1", "ID", "ACC" FROM "ACC1" where "ID" = :ID '>
            <SelectParameters>
             <asp:Parameter Name="ID" Type="String" />
            </SelectParameters>
                    </asp:SqlDataSource>

解决方案 »

  1.   

    为什么不在后台代码写呢?过滤后再绑定如果要选中一个可以参考SDK里面<%@ Page language="C#" %><script runat="server">  void CustomersGridView_SelectedIndexChanged(Object sender, EventArgs e)  
      {
            
        // Display the primary key value of the selected row.
        Message.Text = "The primary key value of the selected row is " +
          CustomersGridView.SelectedValue.ToString() + ".";
        
      }</script><html>
      <body>
        <form runat="server">
            
          <h3>GridView SelectedValue Example</h3>
                
          <asp:label id="Message"
            forecolor="Red"
            runat="server"/>
                    
          <br/><br/>      <asp:gridview id="CustomersGridView" 
            datasourceid="CustomersSource" 
            allowpaging="true"
            autogeneratecolumns="true"
            autogenerateselectbutton="true"    
            datakeynames="CustomerID"
            onselectedindexchanged="CustomersGridView_SelectedIndexChanged"   
            runat="server">
                    
            <selectedrowstyle backcolor="LightBlue"
              forecolor="DarkBlue"/> 
                   
          </asp:gridview>
                
          <!-- This example uses Microsoft SQL Server and connects  -->
          <!-- to the Northwind sample database. Use an ASP.NET     -->
          <!-- expression to retrieve the connection string value   -->
          <!-- from the Web.config file.                            -->
          <asp:sqldatasource id="CustomersSource"
            selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]"
            connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" 
            runat="server"/>
                
        </form>
      </body>
    </html>