How to place a condition in a template column in the datagrid?
-
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!!!
-
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!!!
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 )
-
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 )
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!!! -
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!!!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 )
-
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!!!
why don't you do this from code behind...it is bit easier from there.......
Ashish Sehajpal