Change Gridview Datasource or Select statement ijn code?

Discussion in 'ASP .Net' started by K B, Jun 8, 2006.

  1. K B

    K B Guest

    Hi. I have a gridview with sqldatasource, etc. For the grid, I also have
    a search textbox. If the user needs to filter the records, I want to
    dynamically adjust the SELECT statement for the SqlDataSource. I like
    all the automatic capabilities for paging, sorting, etc., so I don't
    want to just bind the old way.

    Any clues?

    thanks,
    KB



    *** Sent via Developersdex http://www.developersdex.com ***
     
    K B, Jun 8, 2006
    #1
    1. Advertising

  2. K B

    PeterKellner Guest

    On Wed, 07 Jun 2006 18:07:03 -0700, K B <>
    wrote:

    >Hi. I have a gridview with sqldatasource, etc. For the grid, I also have
    >a search textbox. If the user needs to filter the records, I want to
    >dynamically adjust the SELECT statement for the SqlDataSource. I like
    >all the automatic capabilities for paging, sorting, etc., so I don't
    >want to just bind the old way.
    >
    >Any clues?
    >
    >thanks,
    >KB
    >
    >
    >
    >*** Sent via Developersdex http://www.developersdex.com ***


    The QuickStart's are a great resource for things like this. To change
    your sql statement in a sqldatasource, use the SelectCommand
    attribute. You can set it in code by doing something like:

    SqlDataSource1.SelectCommand = "select * from table";

    http://www.asp.net/QuickStart/util/srcview.aspx?path=~/aspnet/samples/data/GridViewSimple.src

    <%@ Page Language="C#" %>
    <html>
    <head runat="server">
    <title>GridView Bound to SqlDataSource</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" DataSourceID="SqlDataSource1"
    runat="server" />
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
    SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone],
    [address], [city], [state], [zip], [contract] FROM [authors]"
    ConnectionString="<%$ ConnectionStrings:pubs %>" />
    </form>
    </body>
    </html>
    Peter Kellner
    http://peterkellner.net
     
    PeterKellner, Jun 8, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris
    Replies:
    1
    Views:
    1,370
    Alexey Smirnov
    May 10, 2007
  2. pradeep
    Replies:
    0
    Views:
    156
    pradeep
    May 25, 2006
  3. jobs
    Replies:
    2
    Views:
    1,715
  4. palmiere
    Replies:
    1
    Views:
    466
    Erwin Moller
    Feb 9, 2004
  5. Bonge Boo!
    Replies:
    5
    Views:
    230
    Bonge Boo!
    Apr 25, 2005
Loading...

Share This Page