ASP.NET WebForms-如何为GridView中的标题行设置colspan?
我想将网格视图中标题行的colspan设置为与下图相同: Html代码是:ASP.NET WebForms-如何为GridView中的标题行设置colspan?,asp.net,gridview,webforms,Asp.net,Gridview,Webforms,我想将网格视图中标题行的colspan设置为与下图相同: Html代码是: <html> <body> <table border="1"> <tr> <th colspan=2>Header</th> </tr> <tr> <td>row 1, cell 1</
<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>
标题
第1行,第1单元
第1行第2单元
第2行第1单元
第2行,第2单元
我不知道如何在asp.net中创建相同的效果,也不想手动使用for循环创建表。谢谢大家! I附加到预渲染事件:
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";
}
protectedvoidbtnaction\u单击(对象发送方,事件参数e)
{
字符串值=txtDetails.Text;
字符[]分隔符=新字符[]{';','['};
string[]parts=value.Split(分隔符,StringSplitOptions.RemoveEmptyEntries);
对于(int i=0;i
嘿,你试过了吗?我想避免使用中继器。如果GridView不支持这一点,那么我将不得不使用中继器:(如果你得到了信息,请接受回答
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();
}
}