我想为网格视图中的标题行设置colspan,使其与下图中的相同:
Html代码是:
<html>
<body>
<table border="1">
<tr>
<th colspan=2>Header</th>
</tr>
<tr>
<td>row 1, cell 1</td>
<td>row 1, cell 2</td>
</tr>
<tr>
<td>row 2, cell 1</td>
<td>row 2, cell 2</td>
</tr>
</table>
</body>
</html>
我不知道如何在asp.net中创建相同的效果,我不想手动使用for循环创建表。
谢谢!
答案 0 :(得分:10)
我附加了PreRender事件:
protected void GridView1_PreRender(object sender, EventArgs e)
{
var gridView = (GridView) sender;
var header = (GridViewRow) gridView.Controls[0].Controls[0];
header.Cells[0].Visible = false;
header.Cells[1].ColumnSpan = 2;
header.Cells[1].Text = "Header";
}
答案 1 :(得分:-1)
protected void btnAction_Click(object sender, EventArgs e)
{
string value = txtDetails.Text;
char[] delimiter = new char[] { ';','[' };
string[] parts = value.Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < parts.Length; i++)
{
txtFName.Text = parts[0].ToString();
txtLName.Text = parts[1].ToString();
txtAge.Text = parts[2].ToString();
txtDob.Text = parts[3].ToString();
}
}