[英]Add "th" to row in gridview
I am trying to achieve the below HTML in a Gridview but not getting the results i require我正在尝试在 Gridview 中实现以下 HTML,但没有得到我需要的结果
<tbody>
<tr>
<th element="row">Name</th>
<td>Data 1 </td>
<td>Data 2 </td>
<td>Data 3</td>
</tr>
<tr></tr>
<tbody>
Im struggling with <th element="row">Name</th>
area.我在<th element="row">Name</th>
区域中挣扎。 In my OnRowDataBound (removed some code for clarity) I have the below在我的 OnRowDataBound(为了清晰起见删除了一些代码)中,我有以下内容
protected void gv1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
TableCellCollection cell = e.Row.Cells;
cell[0].Attributes.Add("th", "element");
}
}
but this produces the below HTML但这会产生以下 HTML
<td th="element">
Other rows seem to be ok.其他行似乎没问题。
My inline code is我的内联代码是
<Columns>
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:Label ID="label1" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
....
How could i achieve the required HTML?我怎样才能实现所需的 HTML?
<th>
needs to be defined on an unique <tr>
, because the <tr>
means the row. <th>
需要在唯一的<tr>
上定义,因为<tr>
表示行。
Example shown here: https://www.w3schools.com/html/html_tables.asp此处显示的示例: https : //www.w3schools.com/html/html_tables.asp
Use the following code to make the header row th
使用下面的代码,以使标题行th
protected void gv1_OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.TableSection = TableRowSection.TableHeader;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.