0

gridview는 sqldatasource1과 자동으로 연결됩니다. 그리드의 경우 검색 텍스트 상자가 있습니다. 사용자가 레코드를 필터링해야하는 경우 다른 (sqldatasource2-another procuder ,ASP.NET을 사용하여 Gridview 데이터 소스 변경 SQLDATASOURCE

을 sqldatasource1 및 sqldatasource2 반환 같은 질의 :))과 ..

메모를 ... 같은있는 gridview에 넣어, 그래서 다른의 SqlDataSource에 gridView.datasourceID을 변경해야 할 버튼을 온 클릭 sqldatasource1의 procuder :

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 

sqldatasource2의 procuder ((searche) :

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 [email protected] and [email protected] 
       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 [email protected] and ID_Entreprise in(select ID_Entreprise 
                  from dbo.Entreprise 
                  where [email protected])            
       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 

이있는 검색 텍스트 및 버튼 :

<div class="GridViewDiv"> 

       <asp:UpdatePanel ID="DossierUpdatePanel" runat="server" UpdateMode="Conditional" > 
        <ContentTemplate> 
         <asp:SqlDataSource ID="Dossier" runat="server" 
           ConnectionString="<%$ ConnectionStrings:OfficeConnectionString %>" 
           SelectCommand="AfficheDossiers" SelectCommandType="StoredProcedure"> 
            <SelectParameters> 
             <asp:SessionParameter Name="Nom_GIAC" SessionField="Nom_GIAC" Type="String" /> 
            </SelectParameters> 
          </asp:SqlDataSource> 

         <asp:SqlDataSource ID="RechercheDossierDS" runat="server" 
          ConnectionString="<%$ ConnectionStrings:OfficeConnectionString %>" 
          SelectCommand="rechercherGIAC" SelectCommandType="StoredProcedure"> 
          <SelectParameters> 
           <asp:SessionParameter Name="nomgiac" SessionField="Nom_GIAC" Type="String" /> 
           <asp:ControlParameter ControlID="RecherhcerComboBox" Name="nom" 
            PropertyName="SelectedValue" Type="String" /> 
           <asp:SessionParameter Name="par" SessionField="Recherche" Type="String" /> 
          </SelectParameters> 
         </asp:SqlDataSource> 
         <asp:GridView ID="DossierGV" runat="server" AllowPaging="True" AllowSorting="True" 
      DataSourceID="Dossier" AutoGenerateColumns="False" DataKeyNames="ID_Dossier"> 
          <Columns> 
           <asp:CommandField ShowSelectButton="True" /> 
           <asp:BoundField DataField="ID_Dossier" HeaderText="ID_Dossier" ReadOnly="True" 
            SortExpression="ID_Dossier" /> 
           <asp:BoundField DataField="ID_Entreprise" HeaderText="ID_Entreprise" 
            SortExpression="ID_Entreprise" /> 
           <asp:BoundField DataField="Date_Dépôt" HeaderText="Date_Dépôt" 
            SortExpression="Date_Dépôt" /> 
           <asp:BoundField DataField="Type_Etude" HeaderText="Type_Etude" 
            SortExpression="Type_Etude" /> 
           <asp:BoundField DataField="Dernier_Type" HeaderText="Dernier_Type" 
            SortExpression="Dernier_Type" /> 
           <asp:BoundField DataField="Eligibilité" HeaderText="Eligibilité" 
            SortExpression="Eligibilité" /> 
           <asp:BoundField DataField="Fiche_Information" HeaderText="Fiche_Information" 
            SortExpression="Fiche_Information" /> 
           <asp:BoundField DataField="Bulletin_d’adhésion" HeaderText="Bulletin_d’adhésion" 
            SortExpression="Bulletin_d’adhésion" /> 
           <asp:BoundField DataField="Fiche_Renseignment" HeaderText="Fiche_Renseignment" 
            SortExpression="Fiche_Renseignment" /> 
           <asp:BoundField DataField="Attestation" HeaderText="Attestation" 
            SortExpression="Attestation" /> 
           <asp:BoundField DataField="Date_Début" HeaderText="Date_Début" 
            SortExpression="Date_Début" /> 
           <asp:BoundField DataField="Date_Fin" HeaderText="Date_Fin" 
            SortExpression="Date_Fin" /> 
           <asp:BoundField DataField="ID_Cabinet" HeaderText="ID_Cabinet" 
            SortExpression="ID_Cabinet" /> 
           <asp:BoundField DataField="Montant_Demander" HeaderText="Montant_Demander" 
            SortExpression="Montant_Demander" /> 
           <asp:BoundField DataField="Durée" HeaderText="Durée" SortExpression="Durée" /> 
           <asp:BoundField DataField="Pourcentage,Taux" HeaderText="Pourcentage,Taux" 
            SortExpression="Pourcentage,Taux" /> 
          </Columns> 
         </asp:GridView> 
        </ContentTemplate> 
       </asp:UpdatePanel> 
     </div>  

모든 단서 :

Saisir la CNSS : 
        <asp:TextBox ID="CNSSTxt" class="TXTBOX" runat="server" Height="23px" placeholder="CNSS" style="font-family : Comic Sans MS, Arial, Tahoma; color:Red;"></asp:TextBox> 

        <asp:Button ID="BtnFiltrerCNSS" runat="server" Text="Filtrer" class="BTN" style="font-variant:small-caps;" /> 

이가있는 gridview는?

덕분에, 단지 설정된 온 클릭 버튼 이벤트에서

+0

일부 코드를 표시 할 수 있습니까? 당신의 질문과는 별도로? 어디서 당신의 데이터 소스를 바인딩합니까, 버튼 클릭 방법에 무엇이 있습니까? – Thousand

+0

내 질문 업데이트 ^^ –

답변

3

gridview.datasource = newDataSource;

이어서

girdView.DataBind()을 호출;

내가 필요한 경우 알려주십시오.

Visual Studio 2010을 사용하는 경우 .aspx 파일을 클릭 한 다음 창의 오른쪽 아래에있는 디자인보기를 클릭해야합니다. 이렇게하면 화면이 갑자기 열리 며 클릭 이벤트를 원하는 버튼을 두 번 클릭하면됩니다. 그런 다음 코드 숨김 파일 (.aspx.cs)로 리디렉션됩니다. 그 방법에서 당신이 이것을 쓸 필요가있다. 나는 당신의 버튼을 당신은 조건에 따라 코드 뒤에 데이터 소스를 제공 할 수없는 onclick을 = "methodName로"속성

+0

나는 이것을 시도하지만 작동하지 않습니다 : s : s –

+0

제 편집을 참조하십시오. 중단 점을 설정하고 디버깅 할 경우 코드 숨김에서 onclick 이벤트로 이동하는 코드가 있습니까? – joncodo

1

을 가지고보기 때문에

는 난 단지 지금이 말을.

if(someCondition) 
     myStoredProcedure = "storedProc1"; 
    else 
     myStoredProcedure = "storedProc2"; 

    SqlDataSource dataSource = new SqlDataSource(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString, searchQuery); 
    dataSource.SelectCommandType = SqlDataSourceCommandType.StoredProcedure; 
    dataSource.SelectCommand = myStoredProcedure; 
    dataSource.ID = "myDataSource"; 

    // Your code to set datasource to grid 

    gridBookings.DataSourceID = dataSource.ID; 
    gridBookings.DataBind(); 
+0

나는 정신을 잃을 까봐 두려웠다. myStoredProcedure = "storedProc1"; –

+0

네,이게 tnkkss예요. 이제 이해 해요 ^^ Adil 아라비아 이름 tnks 다시 동생 –

+0

오빠 환영합니다. – Adil

관련 문제