Change Gridview Datasource or Select statement ijn code?

K

K B

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
 
P

PeterKellner

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

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top