8

当我使用超链接创建“TemplateField”时,如何在 GridView 中创建标题“全名”?例如,我希望 TemplateField 中的这些行具有标题“全名”。

<asp:GridView ID="CustomersGridView" runat="server" AutoGenerateColumns="False" >
        <Columns>

            <asp:TemplateField>
                <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("FirstName") + " " + Eval("LastName")  %>'
                     NavigateUrl="CarTest.aspx" > </asp:HyperLink>        
                </ItemTemplate>
            </asp:TemplateField>

        </Columns>
</asp:GridView>
4

3 回答 3

18

使用标题模板:

 <Columns>
    <asp:TemplateField>
          <ItemTemplate>
               ....................
          </ItemTemplate>
          <HeaderTemplate>
                Full Name
         </HeaderTemplate>
     </asp:TemplateField>
  </Columns>

有关更多信息,请阅读

于 2013-01-31T19:40:29.123 回答
7
<asp:GridView ID="CustomersGridView" runat="server" AutoGenerateColumns="False" >
    <Columns>

        <asp:TemplateField HeaderText="Full Name">
            <ItemTemplate>
            <asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("FirstName") + " " + Eval("LastName")  %>'
                 NavigateUrl="CarTest.aspx" > </asp:HyperLink>        
            </ItemTemplate>
        </asp:TemplateField>

    </Columns>
</asp:GridView>
于 2013-01-31T19:45:21.627 回答
0
<div class="table-responsive">
                                                                        <asp:GridView ID="grdDisCategry" runat="server" CssClass="table table-small-font table-bordered table-striped" Font-Size="Small"
                                                                            EmptyDataRowStyle-ForeColor="#cc0000" HeaderStyle-Font-Size="10" HeaderStyle-Font-Names="Arial"
                                                                            AutoGenerateColumns="False" EmptyDataText="No Record Found" HeaderStyle-ForeColor="#990000">
                                                                            <Columns>
<asp:TemplateField HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign="Center">
                                                                                    <HeaderTemplate>

                                                                                        <asp:TextBox ID="txtMonthsDays" runat="server" class="form-control input-sm m-bot15"
                                                                                            Font-Bold="true" Text='<%#Bind("MonthsDays") %>'></asp:TextBox>
                                                                                    </HeaderTemplate>
                                                                                    <ItemTemplate>

                                                                                        <asp:TextBox ID="txtMonthDays" runat="server" class="form-control input-sm m-bot15"
                                                                                            Font-Bold="true" Text='<%#Bind("MonthDays") %>'></asp:TextBox>

                                                                                    </ItemTemplate>
                                                                                    <HeaderStyle HorizontalAlign="Center"></HeaderStyle>
                                                                                    <ItemStyle HorizontalAlign="Center" Width="80px" />
                                                                                </asp:TemplateField>
 </Columns>
                                                                            <HeaderStyle HorizontalAlign="Justify" VerticalAlign="Top"
                                                                                Font-Bold="true" />
                                                                            <RowStyle Font-Size="Small" Height="1" ForeColor="#000000" Font-Italic="true" />
                                                                        </asp:GridView>
于 2019-05-15T05:14:23.907 回答