views:

25

answers:

1

Hello Everyone,

I was trying to do this :

  <asp:GridView ID="gvBugList" runat="server" AutoGenerateColumns="False" ShowHeader="False"
      DataSourceID="linqDSBugList" Width="100%" AllowPaging="true" PageSize="20" DataKeyNames="BugID">
      <Columns>
        <asp:TemplateField>
          <ItemTemplate>
            <div class="messageHeader" id='<%# String.Format("Message_{0}",Eval("BugID")) %>' style='<% if(Eval("Status") == true) return "background:green";%>'>
              <a href="#" onclick="BuggyBag.openMesage(this)">
                <%#Eval("Subject") %></a>
            </div>
            <div class="messageCollapse">
              <b>Message :</b><p>
                <%# Eval("Message") %>
              </p>
              <input type="button" onclick="BuggyBag.SetStatus(this,true)" value="Set Resolved"
                id='<%#Eval("BugID") %>' />
            </div>
          </ItemTemplate>
        </asp:TemplateField>
  </Columns>
</asp:GridView>

In this code I want to change messageHeader style properties according to Status field whose data coming from database. How can I do that with inline scripting. As you may see I tried to do that at style attr of messageHeader but it wouldn't work out.

Thanks.

+2  A: 

Inside your style attribute you need to put the following:

<%= ((bool)Eval("Status")) ? "background:green" : "" %>
Darko Z
Actually it doesn't work on my problem. But I found the solution after changing your code a little bit : `style=<%# ((bool)Eval("Status") == true) ? "background:green" : "" %>`
Braveyard
Bummer, I haven't done Evals and Binds in so long (thanks MVC) that I forgot the cast. Have updated with your code.
Darko Z
Is MVC really worth to leave old school web pages ?
Braveyard
Its not for everyone but for me its about 100 billion times better than regular ASP.NET. Just so much more control over the HTML
Darko Z