2012-01-04 4 views
0

Я хочу, чтобы стиль сетки вид, как я должен показать 4 ордера на сетке вид, в котором 2 порядок имеет статус истины и 2 порядок имеет статус ложь теперь я хочу применить стиль, как тот порядок имеют ложный статус должен видна в желтом цвете и те заказы истинны должен виден в обычном цвете, как черные вот мой вид сеткиGrid View Styling Asp.Net

<asp:GridView ID="CateringGridView" runat="server" AutoGenerateColumns="false" DataKeyNames="Id"> 
        <RowStyle CssClass="GridRow" /> 
        <Columns> 
         <asp:TemplateField HeaderText="First Name"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("FirstName") %>'></asp:Label> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Last Name"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("LastName") %>'></asp:Label> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Company Name"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("CompanyName") %>'></asp:Label> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Email"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("Email") %>'></asp:Label> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Phone"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("Phone") %>'></asp:Label> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="People Attending"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("PeopleAttending") %>'></asp:Label> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Event Type"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("TypeOfEvent") %>'></asp:Label> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Event Date"> 
          <ItemTemplate> 
           <asp:Label ID="Label1" runat="server" Text='<%#Bind("DateOfEvent") %>'></asp:Label> 
          </ItemTemplate> 
         </asp:TemplateField> 
        </Columns> 
       </asp:GridView> 

и мой код позади файла

protected void Page_Load(object sender, EventArgs e) 
     { 
      if (!IsPostBack) 
      { 
       this.FillCateringGrid(); 
      } 
     } 

     private void FillCateringGrid() 
     { 
      using (CateringOrderDataContext dataContext = new CateringOrderDataContext()) 
      { 
       var query = dataContext.Caterings 
             .Where(e => e.Status == true) 
             .Select(e => e); 
       this.CateringGridView.DataSource = query; 
       this.CateringGridView.DataBind(); 
      } 
     } 

ответ

2
<RowStyle CssClass='<%=((Catering)Container.DataItem).Status ? "A" : "B"%>' /> 

Где A и B - c lass на основе того, является ли Status истинным или ложным. то вы можете определить формат CSS для td.A и td.B.

+0

не работает –

+0

ухаживать? –

+1

Я не понимаю, что вы пытаетесь сказать, что я просто скопирую ваш код и давая мне ошибку. Выражения для привязки данных поддерживаются только объектами, имеющими событие DataBinding. System.Web.UI.WebControls.TableItemStyle не имеет события DataBinding. –