title: Change Gridview Datasource using ASP .NET SQLDATASOURCE
body: <p>i have a gridview automaticly connecting with sqldatasource1, etc. For the grid, I also have a search textbox  If the user needs to filter the records it calls an another ((sqldatasource2-another procuder)) and put it in the same gridview ..,so i need to change the gridView.datasourceID to the another sqldatasource onclick a button .. </p>
  
  <p>note :
  sqldatasource1 and sqldatasource2 returning the same queries ,</p>
  
  <p>the procuder of sqldatasource1 :</p>
  
  <pre><code>create proc AfficheDossiers
  @Nom_GIAC varchar(50)
  as
   begin
   select [ID_Dossier] as 'ID_Dossier'
        ,[ID_Entreprise] as 'ID_Entreprise'
        ,[Date_Depot] as 'Date_Dépôt'
        ,[Type_Etude] as 'Type_Etude'
        ,[Dernier_Type] as 'Dernier_Type'
        ,[Eligibile] as 'Eligibilité'
        ,[Fiche_Information] as 'Fiche_Information'
        ,[Buletin_Adhesion] as 'Bulletin_d’adhésion'
        ,[Fiche_Renseignment] as 'Fiche_Renseignment'
        ,[Attestation] as 'Attestation'
        ,[Date_Debut] as 'Date_Début'
        ,[Date_Fin] as 'Date_Fin'
        ,[ID_Cabinet] as 'ID_Cabinet'
        ,[Montant_Demander] as 'Montant_Demander'
        ,[Duree] as 'Durée'
        ,[Porcentage_Taux] as 'Pourcentage,Taux' from Dossier where Nom_Giac = @Nom_GIAC 
   end
  </code></pre>
  
  <p>the procuder of sqldatasource2((searche) :</p>
  
  <pre><code>alter proc rechercherGIAC @nomgiac varchar(20),@nom varchar(30),@par varchar(50)
             as
              begin
              if @nom='CNSS' 
                begin
                select d.[ID_Dossier] as 'ID_Dossier'
                ,d.[ID_Entreprise] as 'ID_Entreprise'
                ,[Date_Depot] as 'Date_Dépôt'
                ,[Type_Etude] as 'Type_Etude'
                ,[Dernier_Type] as 'Dernier_Type'
                ,[Eligibile] as 'Eligibilité'
                ,[Fiche_Information] as 'Fiche_Information'
                ,[Buletin_Adhesion] as 'Bulletin_d’adhésion'
                ,[Fiche_Renseignment] as 'Fiche_Renseignment'
                ,[Attestation] as 'Attestation'
                ,[Date_Debut] as 'Date_Début'
                ,[Date_Fin] as 'Date_Fin'
                ,[ID_Cabinet] as 'ID_Cabinet'
                ,[Montant_Demander] as 'Montant_Demander'
                ,[Duree] as 'Durée'
                ,[Porcentage_Taux] as 'Pourcentage,Taux' 
                from dbo.Dossier d inner join entreprise e on d.ID_Entreprise=e.ID_Entreprise
                where CNSS_Entreprise=@par and d.Nom_Giac=@nomgiac 
                end
              else if @nom='RS'  
                begin
                select [ID_Dossier] as 'ID_Dossier'
                ,[ID_Entreprise] as 'ID_Entreprise'
                ,[Date_Depot] as 'Date_Dépôt'
                ,[Type_Etude] as 'Type_Etude'
                ,[Dernier_Type] as 'Dernier_Type'
                ,[Eligibile] as 'Eligibilité'
                ,[Fiche_Information] as 'Fiche_Information'
                ,[Buletin_Adhesion] as 'Bulletin_d’adhésion'
                ,[Fiche_Renseignment] as 'Fiche_Renseignment'
                ,[Attestation] as 'Attestation'
                ,[Date_Debut] as 'Date_Début'
                ,[Date_Fin] as 'Date_Fin'
                ,[ID_Cabinet] as 'ID_Cabinet'
                ,[Montant_Demander] as 'Montant_Demander'
                ,[Duree] as 'Durée'
                ,[Porcentage_Taux] as 'Pourcentage,Taux'  
                from dbo.Dossier 
                where  Nom_Giac=@nomgiac and ID_Entreprise in( select ID_Entreprise
                                                               from dbo.Entreprise
                                                               where Raison_Social=@par)                                            
                end
             else if @nom ='Date'
              begin
               declare @v smalldatetime,@b smalldatetime
                set @b=SUBSTRING(@par,1,4)
                set @v=SUBSTRING(@par,5,8)
              select [ID_Dossier] as 'ID_Dossier'
                ,[ID_Entreprise] as 'ID_Entreprise'
                ,[Date_Depot] as 'Date_Dépôt'
                ,[Type_Etude] as 'Type_Etude'
                ,[Dernier_Type] as 'Dernier_Type'
                ,[Eligibile] as 'Eligibilité'
                ,[Fiche_Information] as 'Fiche_Information'
                ,[Buletin_Adhesion] as 'Bulletin_d’adhésion'
                ,[Fiche_Renseignment] as 'Fiche_Renseignment'
                ,[Attestation] as 'Attestation'
                ,[Date_Debut] as 'Date_Début'
                ,[Date_Fin] as 'Date_Fin'
                ,[ID_Cabinet] as 'ID_Cabinet'
                ,[Montant_Demander] as 'Montant_Demander'
                ,[Duree] as 'Durée'
                ,[Porcentage_Taux] as 'Pourcentage,Taux'  
              from Dossier 
              where Date_Depot between @b and @v and Nom_Giac like @nomgiac
  
              end 
              end
  </code></pre>
  
  <p>this is the search text and button : </p>
  
  <pre><code> Saisir la CNSS : 
                       &lt;asp:TextBox ID="CNSSTxt" class="TXTBOX" runat="server" Height="23px" placeholder="CNSS" style="font-family : Comic Sans MS, Arial, Tahoma; color:Red;"&gt;&lt;/asp:TextBox&gt;
  
                       &lt;asp:Button ID="BtnFiltrerCNSS" runat="server" Text="Filtrer" class="BTN" style="font-variant:small-caps;" /&gt;
  </code></pre>
  
  <p>this is the gridview : </p>
  
  <pre><code> &lt;div class="GridViewDiv"&gt;
  
                &lt;asp:UpdatePanel ID="DossierUpdatePanel" runat="server" UpdateMode="Conditional" &gt;
                    &lt;ContentTemplate&gt;
                        &lt;asp:SqlDataSource ID="Dossier" runat="server" 
                                ConnectionString="&lt;%$ ConnectionStrings:OfficeConnectionString %&gt;" 
                                SelectCommand="AfficheDossiers" SelectCommandType="StoredProcedure"&gt;
                                     &lt;SelectParameters&gt;
                                         &lt;asp:SessionParameter Name="Nom_GIAC" SessionField="Nom_GIAC" Type="String" /&gt;
                                     &lt;/SelectParameters&gt;
                            &lt;/asp:SqlDataSource&gt;
  
                        &lt;asp:SqlDataSource ID="RechercheDossierDS" runat="server" 
                            ConnectionString="&lt;%$ ConnectionStrings:OfficeConnectionString %&gt;" 
                            SelectCommand="rechercherGIAC" SelectCommandType="StoredProcedure"&gt;
                            &lt;SelectParameters&gt;
                                &lt;asp:SessionParameter Name="nomgiac" SessionField="Nom_GIAC" Type="String" /&gt;
                                &lt;asp:ControlParameter ControlID="RecherhcerComboBox" Name="nom" 
                                    PropertyName="SelectedValue" Type="String" /&gt;
                                &lt;asp:SessionParameter Name="par" SessionField="Recherche" Type="String" /&gt;
                            &lt;/SelectParameters&gt;
                        &lt;/asp:SqlDataSource&gt;
                        &lt;asp:GridView ID="DossierGV" runat="server" AllowPaging="True" AllowSorting="True" 
            DataSourceID="Dossier" AutoGenerateColumns="False" DataKeyNames="ID_Dossier"&gt;
                            &lt;Columns&gt;
                                &lt;asp:CommandField ShowSelectButton="True" /&gt;
                                &lt;asp:BoundField DataField="ID_Dossier" HeaderText="ID_Dossier" ReadOnly="True" 
                                    SortExpression="ID_Dossier" /&gt;
                                &lt;asp:BoundField DataField="ID_Entreprise" HeaderText="ID_Entreprise" 
                                    SortExpression="ID_Entreprise" /&gt;
                                &lt;asp:BoundField DataField="Date_Dépôt" HeaderText="Date_Dépôt" 
                                    SortExpression="Date_Dépôt" /&gt;
                                &lt;asp:BoundField DataField="Type_Etude" HeaderText="Type_Etude" 
                                    SortExpression="Type_Etude" /&gt;
                                &lt;asp:BoundField DataField="Dernier_Type" HeaderText="Dernier_Type" 
                                    SortExpression="Dernier_Type" /&gt;
                                &lt;asp:BoundField DataField="Eligibilité" HeaderText="Eligibilité" 
                                    SortExpression="Eligibilité" /&gt;
                                &lt;asp:BoundField DataField="Fiche_Information" HeaderText="Fiche_Information" 
                                    SortExpression="Fiche_Information" /&gt;
                                &lt;asp:BoundField DataField="Bulletin_d’adhésion" HeaderText="Bulletin_d’adhésion" 
                                    SortExpression="Bulletin_d’adhésion" /&gt;
                                &lt;asp:BoundField DataField="Fiche_Renseignment" HeaderText="Fiche_Renseignment" 
                                    SortExpression="Fiche_Renseignment" /&gt;
                                &lt;asp:BoundField DataField="Attestation" HeaderText="Attestation" 
                                    SortExpression="Attestation" /&gt;
                                &lt;asp:BoundField DataField="Date_Début" HeaderText="Date_Début" 
                                    SortExpression="Date_Début" /&gt;
                                &lt;asp:BoundField DataField="Date_Fin" HeaderText="Date_Fin" 
                                    SortExpression="Date_Fin" /&gt;
                                &lt;asp:BoundField DataField="ID_Cabinet" HeaderText="ID_Cabinet" 
                                    SortExpression="ID_Cabinet" /&gt;
                                &lt;asp:BoundField DataField="Montant_Demander" HeaderText="Montant_Demander" 
                                    SortExpression="Montant_Demander" /&gt;
                                &lt;asp:BoundField DataField="Durée" HeaderText="Durée" SortExpression="Durée" /&gt;
                                &lt;asp:BoundField DataField="Pourcentage,Taux" HeaderText="Pourcentage,Taux" 
                                    SortExpression="Pourcentage,Taux" /&gt;
                            &lt;/Columns&gt;
                        &lt;/asp:GridView&gt;
                    &lt;/ContentTemplate&gt;
                &lt;/asp:UpdatePanel&gt;
         &lt;/div&gt;     
  </code></pre>
  
  <p>Any clues?</p>
  
  <p>thanks,</p>