locked
Where and how should I code the <%$ Eval("Region") %> as a subtitle for a GridView? RRS feed

  • Question

  • User-830563764 posted

    In a VS2010 ASP.net 4 webpage, I have a GridView control displaying data from a SqlDataSource.
    There is a selected column, Region, for the GridView.  I would like to display the Region name with
    a bold and big font, as a subtitle. 

    Where and how should I code the <h3><%$ Eval("Region") %></h3>?
    I tried coding between the GridView and SqlDataSource codes, but no good.

    Thursday, June 9, 2016 6:44 PM

Answers

  • User61956409 posted

    Hi wonjartran,

    I would like to display the Region name with a bold and big font, as a subtitle. 

    Firstly, you could modify the code to this.

    <asp:TemplateField>
        <ItemTemplate>
            <h3><%#Eval("Region") %></h3>
        </ItemTemplate>
    </asp:TemplateField>
    

    Secondly, you could try to use BoundField and specify ItemStyle-CssClass property.

    .myclass {
        font-size: large;
        font-weight: bold;
    }
    
    <asp:BoundField DataField="Region" HeaderText="Region" ItemStyle-CssClass="myclass" />

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 10, 2016 3:08 AM
  • User-1377768212 posted

    Hi,

    wonjartran

    Where and how should I code the <h3><%$ Eval("Region") %></h3>?

    Instead of use #.

    Try this :

    <asp:TemplateField>
        <ItemTemplate>
           <b><h3><%#Eval("Region") %></h3></b>
        </ItemTemplate>
    </asp:TemplateField>

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 10, 2016 5:07 AM
  • User61956409 posted

    Hi wonjartran,

    Firstly, as I mentioned in my previous reply, if you’d like to set special style for BoundField, you could specify CSS style via ItemStyle-CssClass property.

    Secondly, if you’d like to use TemplateField to display subtitle and create nested GridView, you could refer to this article.

    http://www.aspsnippets.com/Articles/Nested-GridView-Example-in-ASPNet-using-C-and-VBNet.aspx

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 14, 2016 8:59 AM

All replies

  • User61956409 posted

    Hi wonjartran,

    I would like to display the Region name with a bold and big font, as a subtitle. 

    Firstly, you could modify the code to this.

    <asp:TemplateField>
        <ItemTemplate>
            <h3><%#Eval("Region") %></h3>
        </ItemTemplate>
    </asp:TemplateField>
    

    Secondly, you could try to use BoundField and specify ItemStyle-CssClass property.

    .myclass {
        font-size: large;
        font-weight: bold;
    }
    
    <asp:BoundField DataField="Region" HeaderText="Region" ItemStyle-CssClass="myclass" />

    Best Regards,

    Fei Han



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 10, 2016 3:08 AM
  • User-1377768212 posted

    Hi,

    wonjartran

    Where and how should I code the <h3><%$ Eval("Region") %></h3>?

    Instead of use #.

    Try this :

    <asp:TemplateField>
        <ItemTemplate>
           <b><h3><%#Eval("Region") %></h3></b>
        </ItemTemplate>
    </asp:TemplateField>

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 10, 2016 5:07 AM
  • User-830563764 posted

    Fei Han,

    In my GridView data control, I used <Columns> to display the <asp:BoundField DataField..>
    <%# Eval("Region") %> does not allowed to be coded inside the <Columns>.

    My question is how to code the <ItemTemplate>as a data row (i.e. a subtitle) for the GridView?

    Monday, June 13, 2016 1:36 PM
  • User61956409 posted

    Hi wonjartran,

    Firstly, as I mentioned in my previous reply, if you’d like to set special style for BoundField, you could specify CSS style via ItemStyle-CssClass property.

    Secondly, if you’d like to use TemplateField to display subtitle and create nested GridView, you could refer to this article.

    http://www.aspsnippets.com/Articles/Nested-GridView-Example-in-ASPNet-using-C-and-VBNet.aspx

    Best Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 14, 2016 8:59 AM