0

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.

1 Answer 1

2

Inside your style attribute you need to put the following:

<%= ((bool)Eval("Status")) ? "background:green" : "" %>
Sign up to request clarification or add additional context in comments.

4 Comments

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" : "" %>
Bummer, I haven't done Evals and Binds in so long (thanks MVC) that I forgot the cast. Have updated with your code.
Is MVC really worth to leave old school web pages ?
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.