[英]insert a row with one column datagridview c#
i want to insert a row to a datagridview in c#.net winform, that have one cell (it means merging cells).我想在 c#.net winform 中的 datagridview 中插入一行,它有一个单元格(这意味着合并单元格)。 i use this row as title of later rows.
我将此行用作后面行的标题。 is there any solution to answer this need?
有什么解决方案可以满足这种需求吗?
tnx tnx
I'm not sure what you are trying to do, can you provide a little more detail on what you are trying to accomplish, and with some data samples?我不确定您要做什么,您能否提供更多有关您要完成的工作的详细信息以及一些数据样本? what version of .net are you targeting?
您的目标是什么版本的 .net?
here is a little bit of code that combines two columns into one column, not sure if this is what you are after.这是一些将两列合并为一列的代码,不确定这是否是您所追求的。
*.aspx *.aspx
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server">
<Columns>
<asp:TemplateField HeaderText="CombinedHeader">
<ItemTemplate>
<asp:Label ID="lblBreakDown" runat="server" Text='<%# string.Format("{0} ({1})",Eval("Column1"),Eval("Column2") ) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.aspx.cs .aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtTemp = new DataTable();
dtTemp.Columns.Add("Column1", typeof(System.String));
dtTemp.Columns.Add("Column2", typeof(System.String));
DataRow drRow1 = dtTemp.NewRow();
drRow1[0] = "Data1";
drRow1[1] = "Data2";
dtTemp.Rows.Add(drRow1);
GridView1.DataSource = dtTemp;
GridView1.DataBind();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.