简体   繁体   中英

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). i use this row as title of later rows. is there any solution to answer this need?

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?

here is a little bit of code that combines two columns into one column, not sure if this is what you are after.

*.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

    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();
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM