I need the SelectCommand to take it from within the <script> because I need to make it so the firstname and lastname is retrieved from the Request.QueryString <%@ Control Language="c#" AutoEventWireup="false" Codebehind="default.ascx.cs" Inherits="Octane8.Applications.Announcements.Website.Default" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%> <script language="C#" runat="server"> protected void Page_Load(object sender, EventArgs e){ SqlDataSource1.SelectCommand = "SELECT [ContactStatusID], [ContactStatusID_HideLevel], [OrgName], [Title], [Suffix], [RegionFellow], [PrintFellow], [PrintState], [OnlinePwd], [ReligiousOrgs], [CharitableOrgs], [EducationOrgs], [AgriculturalOrgs], [HealthOrgs], [Created], [Updated], [LastEdit], [LastName], [SalutationID], [SalutationID_HideLevel], [MiddleInit], [FirstName], [PreferredMailingAddressID], [BusinessOrgs], [WebSite], [WebSite_HideLevel], [SectorID], [SectorOther], [SectorID_HideLevel], [SectorRole], [GeographicAreaID], [GeographicAreaID_HideLevel], [CensusDispositionID], [CensusDisplositionID_HideLevel], [InterestAreaOther], [OnlineNoPwd], [Comments], [Comments_HideLevel], [Bio_HideLevel], [Bio], [Picture], [PermissionComments], [Picture_HideLevel], [SocialServiceOrgs], [CommunityDevelopmentOrgs], [AdvocacyOrgs], [ID] FROM [tContact] WHERE Firstname = 'Jim' AND Lastname = 'Kim'"; DetailsView1.DataSource = SqlDataSource1; DetailsView1.DataBind(); } </script> <div> <aspetailsView ID="DetailsView1" runat="server" DataSourceID="SqlDataSource1" Height="50px" Width="125px" AutoGenerateEditButton="True" DefaultMode="Edit" EnablePagingCallbacks="True" EnableTheming="True"> </aspetailsView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Data Source=mssql10.digitalhousing.net;Persist Security Info=True;User ID=KFLA2007;Password=DeeN29SioY30EoiU" SelectCommand="SELECT [ContactStatusID], [ContactStatusID_HideLevel], [OrgName], [Title], [Suffix], [RegionFellow], [PrintFellow], [PrintState], [OnlinePwd], [ReligiousOrgs], [CharitableOrgs], [EducationOrgs], [AgriculturalOrgs], [HealthOrgs], [Created], [Updated], [LastEdit], [LastName], [SalutationID], [SalutationID_HideLevel], [MiddleInit], [FirstName], [PreferredMailingAddressID], [BusinessOrgs], [WebSite], [WebSite_HideLevel], [SectorID], [SectorOther], [SectorID_HideLevel], [SectorRole], [GeographicAreaID], [GeographicAreaID_HideLevel], [CensusDispositionID], [CensusDisplositionID_HideLevel], [InterestAreaOther], [OnlineNoPwd], [Comments], [Comments_HideLevel], [Bio_HideLevel], [Bio], [Picture], [PermissionComments], [Picture_HideLevel], [SocialServiceOrgs], [CommunityDevelopmentOrgs], [AdvocacyOrgs], [ID] FROM [tContact]" UpdateCommand=""> </asp:SqlDataSource> </div>
Instead of doing inline SQL - you can use yoru strongly typed datasets and just pass it in your querystring values and databind to thhe DataTable's that the Datasets push out
Even better if your using .NET 2.0 take a look at objectdatasources they can make reuse very nice later.
But he is already using the datasource object. Reread the original post. ASP.NET has built-in functionality for this : consider the folowing code sample and adapt for your needs <!-- assuming that your URL string looks like www.domain.com/page.aspx?fName=kulrom&lName=mylastname --> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>" ProviderName="<%$ ConnectionStrings:testConnectionString.ProviderName %>" SelectCommand="SELECT [id], [FirstName], [LastName], [field3] FROM [Table1] WHERE FirstName=@fName AND LastName=@lName"> <SelectParameters> <asp:QueryStringParameter Name="fName" Type="String" QueryStringField="fName" /> <asp:QueryStringParameter Name="lName" Type="String" QueryStringField="lName" /> </SelectParameters> </asp:SqlDataSource> Code (vb): HTH Regards