Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to place a condition in a template column in the datagrid?

How to place a condition in a template column in the datagrid?

Scheduled Pinned Locked Moved ASP.NET
helpcsharphtmlcssvisual-studio
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Infernojericho
    wrote on last edited by
    #1

    Hi, I am stuck big time with a problem in Data Grid. I am using C#, in VS.NET 2003. I am writing a simple web mail system, and I am using the datagrid to display the inbox. It is a very standard inbox, nothing fancy, and I am displaying the sender, subject, as well as the date sent. For each message there is an extra column "opened" which denotes whether the message has been read. Here's what I am stuck, I need to BOLD the message subject for those messages which are unread. I have absolutely no idea where to place the codes, the pseudocode is very simple, simply: If the "opened" column for that particular message is NO, then BOLD the subject Where do I place the codes? I tried to place it in the HTML code as well as the codebehind, no luck. Any suggestions??? HELP!!! Thanks!!!

    C A 2 Replies Last reply
    0
    • I Infernojericho

      Hi, I am stuck big time with a problem in Data Grid. I am using C#, in VS.NET 2003. I am writing a simple web mail system, and I am using the datagrid to display the inbox. It is a very standard inbox, nothing fancy, and I am displaying the sender, subject, as well as the date sent. For each message there is an extra column "opened" which denotes whether the message has been read. Here's what I am stuck, I need to BOLD the message subject for those messages which are unread. I have absolutely no idea where to place the codes, the pseudocode is very simple, simply: If the "opened" column for that particular message is NO, then BOLD the subject Where do I place the codes? I tried to place it in the HTML code as well as the codebehind, no luck. Any suggestions??? HELP!!! Thanks!!!

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      First suggestion, post your code so we can point out what you're doing wrong. I would do something like writing a div to contain the text, and then having the style set the font weight via a property that comes from the codebehind, which in turn is passed the opened value, and returns the right string for plain or bold text.

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      I 1 Reply Last reply
      0
      • C Christian Graus

        First suggestion, post your code so we can point out what you're doing wrong. I would do something like writing a div to contain the text, and then having the style set the font weight via a property that comes from the codebehind, which in turn is passed the opened value, and returns the right string for plain or bold text.

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        I Offline
        I Offline
        Infernojericho
        wrote on last edited by
        #3

        Thanks for the reply. Here is the code for the part that displays the Template Column. <asp:TemplateColumn HeaderText="Subject" ItemStyle-CssClass="content"> <HeaderStyle CssClass="subtitle"></HeaderStyle> <ItemStyle Width="350px"></ItemStyle> <ItemTemplate> <asp:HyperLink id="Viewmessage" runat=server CssClass="content" NavigateUrl='<%#"viewmessage.aspx?messageid=" + DataBinder.Eval(Container.DataItem,"messageid") %>'> <font class="content"> <%# DataBinder.Eval(Container.DataItem,"messagesubject") %> </font> </asp:HyperLink> </ItemTemplate> </asp:TemplateColumn> As you can see, the code above only retreives the SUBJECT and displays it. Is it possible to put a IF condition in the HTML Code? It is possible to do something like this? <asp:TemplateColumn HeaderText="Subject" ItemStyle-CssClass="content"> <HeaderStyle CssClass="subtitle"></HeaderStyle> <ItemStyle Width="350px"></ItemStyle> <ItemTemplate> <asp:HyperLink id="Viewmessage" runat=server CssClass="content" NavigateUrl='<%#"viewmessage.aspx?messageid=" + DataBinder.Eval(Container.DataItem,"messageid") %>'> <%# if (DataBinder.Eval(Container.DataItem,"opened") == "no") { SET FONT = BOLD } %> <font class="content"> <%# DataBinder.Eval(Container.DataItem,"messagesubject") %> </font> </asp:HyperLink> </ItemTemplate> </asp:TemplateColumn> Thanks!!!

        C 1 Reply Last reply
        0
        • I Infernojericho

          Thanks for the reply. Here is the code for the part that displays the Template Column. <asp:TemplateColumn HeaderText="Subject" ItemStyle-CssClass="content"> <HeaderStyle CssClass="subtitle"></HeaderStyle> <ItemStyle Width="350px"></ItemStyle> <ItemTemplate> <asp:HyperLink id="Viewmessage" runat=server CssClass="content" NavigateUrl='<%#"viewmessage.aspx?messageid=" + DataBinder.Eval(Container.DataItem,"messageid") %>'> <font class="content"> <%# DataBinder.Eval(Container.DataItem,"messagesubject") %> </font> </asp:HyperLink> </ItemTemplate> </asp:TemplateColumn> As you can see, the code above only retreives the SUBJECT and displays it. Is it possible to put a IF condition in the HTML Code? It is possible to do something like this? <asp:TemplateColumn HeaderText="Subject" ItemStyle-CssClass="content"> <HeaderStyle CssClass="subtitle"></HeaderStyle> <ItemStyle Width="350px"></ItemStyle> <ItemTemplate> <asp:HyperLink id="Viewmessage" runat=server CssClass="content" NavigateUrl='<%#"viewmessage.aspx?messageid=" + DataBinder.Eval(Container.DataItem,"messageid") %>'> <%# if (DataBinder.Eval(Container.DataItem,"opened") == "no") { SET FONT = BOLD } %> <font class="content"> <%# DataBinder.Eval(Container.DataItem,"messagesubject") %> </font> </asp:HyperLink> </ItemTemplate> </asp:TemplateColumn> Thanks!!!

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          You can do this: ]]> // add tags for column here ]]> I may have some details wrong here, but I know I've done a control that added columns to a datagrid in certain modes using code similar to this.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          1 Reply Last reply
          0
          • I Infernojericho

            Hi, I am stuck big time with a problem in Data Grid. I am using C#, in VS.NET 2003. I am writing a simple web mail system, and I am using the datagrid to display the inbox. It is a very standard inbox, nothing fancy, and I am displaying the sender, subject, as well as the date sent. For each message there is an extra column "opened" which denotes whether the message has been read. Here's what I am stuck, I need to BOLD the message subject for those messages which are unread. I have absolutely no idea where to place the codes, the pseudocode is very simple, simply: If the "opened" column for that particular message is NO, then BOLD the subject Where do I place the codes? I tried to place it in the HTML code as well as the codebehind, no luck. Any suggestions??? HELP!!! Thanks!!!

            A Offline
            A Offline
            Ashish Sehajpal
            wrote on last edited by
            #5

            why don't you do this from code behind...it is bit easier from there.......

            Ashish Sehajpal

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups