2012-11-16 34 views
0

我有一個問題,我在數據源的網格視圖中綁定數據,並且在那裏我記錄了不同類型的訂單狀態信息,從1到7開始。我不想在網格視圖中顯示狀態7數據。你能幫助我,我們網格視圖如何隱藏一些特殊類型的數據,當我在asp.net中的網格視圖綁定數據的細節?

<data:EntityGridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" 
         DataSourceID="ActiveOrdersDataSource" Width="100%" DataKeyNames="OrderNo" AllowMultiColumnSorting="false" 
         OnRowCommand="GridView1_RowCommond" OnRowDataBound="GridView1_OnRowDataBound" 
         DefaultSortDirection="Descending" ExcelExportFileName="Export_ActiveOrders.xls"> 
         <Columns> 
          <asp:CommandField ShowSelectButton="True" SelectText="Edit" /> 
          <asp:BoundField DataField="OrderNo" ItemStyle-HorizontalAlign="Center" HeaderText="Order No" SortExpression="[OrderNo]" /> 
          <asp:BoundField DataField="OrderDate" DataFormatString="{0:d}" HtmlEncode="False" 
           HeaderText="Order Date" SortExpression="[OrderDate]" /> 
          <asp:BoundField DataField="PickupCompanyName" HeaderText="Pickup Company" SortExpression="[PickupCompanyName]" Visible="false" /> 
          <asp:BoundField DataField="DeliveryCompanyName" HeaderText="Delivery Company" SortExpression="[DeliveryCompanyName]" Visible="false" /> 
          <data:HyperLinkField HeaderText="Ac.No." ControlStyle-ForeColor="Black" DataContainer="AccountNumberSource" 
           DataTextField="AccountNumber" /> 
           <data:HyperLinkField HeaderText="Client" DataContainer="AccountNumberSource" 
           DataTextField="Name" /> 
           <asp:BoundField DataField="Caller" ItemStyle-HorizontalAlign="Center" HeaderText="Caller" SortExpression="[Caller]" /> 
           <asp:BoundField DataField="Department" ItemStyle-HorizontalAlign="Center" HeaderText="Department" SortExpression="[Department]" /> 
           <asp:BoundField DataField="Reference" HeaderText="Reference" SortExpression="[Reference]" /> 
          <asp:TemplateField HeaderText="Driver" HeaderStyle-HorizontalAlign="Left"> 
           <ItemTemplate> 
            <asp:Label ID="lblDriver" runat="server" Text='<%#Eval("CurrentDriverNumberSource.Name") %>'></asp:Label> 
           </ItemTemplate> 
          </asp:TemplateField> 
          <data:HyperLinkField HeaderText="Service" ControlStyle-ForeColor="Black" DataContainer="ServiceTypeIdSource" 
           DataTextField="Description" /> 
          <data:HyperLinkField HeaderText="Vehicle" ControlStyle-ForeColor="Black" DataContainer="VehicleTypeIdSource" 
           DataTextField="Description" /> 
          <asp:TemplateField HeaderText="Status" HeaderStyle-HorizontalAlign="Left"> 
           <ItemTemplate> 
            <asp:Label ID="lblStatus" runat="server" Text='<%#Eval("StatusID") %>'></asp:Label> 
           </ItemTemplate> 
          </asp:TemplateField> 

          <asp:TemplateField HeaderText="TotalAmount" ItemStyle-HorizontalAlign="Center"> 
              <ItemTemplate> 
              <asp:Label ID="lblAmount" runat="server" Text='<%# Eval("TotalAmount","{0:C2}")%>' ></asp:Label> 
              </ItemTemplate> 
              <ItemStyle HorizontalAlign="Right" /> 
              </asp:TemplateField> 

         </Columns> 

         <EmptyDataTemplate> 
          <b>No Active Orders Found!</b> 
         </EmptyDataTemplate> 
        </data:EntityGridView> 

,以及如何爲數據源,我用這個

<data:ActiveOrdersDataSource ID="ActiveOrdersDataSourcebyCompany" runat="server" SelectMethod="GetPaged" EnablePaging="True" EnableSorting="True" EnableDeepLoad="True"> 
         <DeepLoadProperties Method="IncludeChildren" Recursive="False"> 
          <Types> 
           <data:ActiveOrdersProperty Name="Clients" /> 
           <data:ActiveOrdersProperty Name="Companies" /> 
           <data:ActiveOrdersProperty Name="Drivers" /> 
           <data:ActiveOrdersProperty Name="SalesPeople" /> 
           <data:ActiveOrdersProperty Name="ServiceTypes" /> 
           <data:ActiveOrdersProperty Name="VehicleTypes" /> 
           <data:ActiveOrdersProperty Name="Zones" /> 
           </Types> 
         </DeepLoadProperties> 
         <Parameters> 
         <asp:SessionParameter Name="CompanyId" SessionField="CompanyId" Type="String" /> 
       <data:SqlParameter Name="WhereClause" UseParameterizedFilters ="false"> 
          <Filters> 

      <%--<data:CustomParameter Name="WhereClause" Value="" ConvertEmptyStringToNull="false" /> 
          <data:CustomParameter Name="OrderByClause" Value="" ConvertEmptyStringToNull="false" /> 
          <asp:ControlParameter Name="PageIndex" ControlID="GridView1" PropertyName="PageIndex" 
           Type="Int32" /> 
          <asp:ControlParameter Name="PageSize" ControlID="GridView1" PropertyName="PageSize" 
           Type="Int32" /> 
          <data:CustomParameter Name="RecordCount" Value="0" Type="Int32" />--%> 
         </Parameters> 
        </data:ActiveOrdersDataSource> 
+0

所以,你要隱藏有一個狀態代碼行7?你爲什麼不在你的sql查詢中忽略它們(實體選擇)。此外,你可以使用onrowdatabound事件(你可以谷歌) –

+1

因爲我假設你將要在代碼中分配'WhereClause' SQL參數值,是否有一些原因,你不能附加'和[狀態] < > 7'到它的結尾? –

+0

我知道這個史蒂夫,但問題是,我正在使用nettier體系結構創建XML存儲過程,如果我改變,我添加的東西,它停止工作,否則我定製,所以我發佈這個像你天才人。 –

回答

1

Goutam,

您可以使用過濾器標籤設置要像值:

<Parameters> 
    <data:SqlParameter Name="WhereClause" UseParameterizedFilters="false"> 
    <Filters> 
     <data:ChartOfAccountsFilter Column="Status" ComparisionType="NotContains" DefaultValue="7" /> 
    </Filters> 
    </data:SqlParameter> 
</Parameters> 
1

你可以按照下面的代碼:

Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) 
If e.Row.RowType = DataControlRowType.DataRow Then 
Dim x As String 
x = e.Row.Cells(1).Text 
Dim y As String 
y = e.Row.Cells(8).Text 
If Convert.ToInt32(x) <= Convert.ToInt32(y) Then 
e.Row.ForeColor = System.Drawing.Color.Blue 
End If 
End If 
End Sub 
相關問題