Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
<asp:GridView ID="example" CssClass="table table-striped table-bordered table-hover" AutoGenerateColumns="false" DataKeyNames="ID" runat="server" ClientIDMode="Static" OnPreRender="example_PreRender" OnRowEditing="example_RowEditing" OnRowCancelingEdit="example_RowCancelingEdit" OnRowDeleting="example_RowDeleting" OnRowDataBound="example_RowDataBound">

                                            <columns>

                                                <asp:TemplateField HeaderText="Ürün Seç" ItemStyle-Width="50">

                                                    <itemtemplate>
                                                       
                                                            <asp:CheckBox ID="chcsec" CssClass="form-control" runat="server" />


                                                      
                                                    
                                                

                                                <asp:TemplateField HeaderText="Ürün Ad" ItemStyle-Width="100">
                                                    <itemtemplate>
                                                        <asp:Label ID="lblUrun" runat="server" Text='<%# Eval("UrunAd") %>'>
                                                    
                                                    <edititemtemplate>
                                                        <asp:TextBox ID="txturunad" runat="server" Text='<%# Eval("UrunAd") %>'>
                                                    
                                                


                                                <asp:TemplateField HeaderText="Stok" ItemStyle-Width="50">
                                                    <itemtemplate>
                                                        <asp:Label ID="lblStok" Style="padding: 3px 5px;" runat="server" Text='<%# Eval("Stok") %>'>
                                                    
                                                    <edititemtemplate>
                                                        <asp:TextBox ID="txtstok" Style="padding: 3px 5px;" runat="server" Text='<%# Eval("Stok") %>'>
                                                    
                                                

                                                <asp:TemplateField HeaderText="Fiyat" ItemStyle-Width="50">
                                                    <itemtemplate>
                                                        <asp:Label ID="txtfiyat" Style="padding: 3px 5px;" CssClass="form-control" runat="server">500
                                                    
                                                    <edititemtemplate>
                                                        <asp:TextBox ID="txtfiyat" Style="padding: 3px 5px;" runat="server" CssClass="form-control">
                                                    
                                                

                                                <asp:TemplateField HeaderText="Adet" ItemStyle-Width="50">
                                                   <itemtemplate>
                                                        <asp:Label ID="txtAdet" Style="padding: 3px 5px;" CssClass="form-control" runat="server">
                                                    
                                                    <edititemtemplate>
                                                        <asp:TextBox ID="txtAdet" runat="server" Style="padding: 3px 5px;" CssClass="form-control">
                                                    
                                                



                                                <asp:TemplateField HeaderText="Eleman Seç" ItemStyle-Width="100">

                                                    <itemtemplate>
                                                        <asp:DropDownList ID="drpEleman" CssClass="form-control" runat="server">
                                                    


                                                

                                                <asp:TemplateField HeaderText="Eleman Adet" ItemStyle-Width="50">
                                                    <itemtemplate>
                                                        <asp:Label ID="txtElemanAdet" Style="padding: 3px 5px;" CssClass="form-control" runat="server">
                                                    
                                                    <edititemtemplate>
                                                        <asp:TextBox ID="txtElemanAdet" runat="server" Style="padding: 3px 5px;" CssClass="form-control">
                                                    
                                                

                                                <asp:TemplateField HeaderText="Eleman Fiyat" ItemStyle-Width="50">
                                                    <itemtemplate>
                                                        <asp:Label ID="txtElemanFiyat" Style="padding: 3px 5px;" CssClass="form-control" runat="server">
                                                    
                                                    <edititemtemplate>
                                                        <asp:TextBox ID="txtElemanFiyat" runat="server" Style="padding: 3px 5px;" CssClass="form-control">
                                                    
                                                

                                         

                                                <asp:CommandField ButtonType="Link" ShowEditButton="true" ShowDeleteButton="true" ItemStyle-Width="150" />


What I have tried:

C#
Hi everyone. I have two gridview. When I selected checkbox I want to copy to gridview another gridview. How can I do this.
Posted
Updated 22-Nov-16 9:59am

1 solution

How about using this function

C#
public System.Web.UI.WebControls.GridView CopyGridView(System.Web.UI.WebControls.GridView p_GridviewToCopy)
{
    System.Web.UI.WebControls.GridView returnCoppiedGridView = new System.Web.UI.WebControls.GridView();
    DataTable copiedTable = new DataTable();
    DataColumn newColumn = null;
    DataRow newRow = null;

    //create columns
    for (int columnIndex = 0; columnIndex < p_GridviewToCopy.Columns.Count; columnIndex++)
    {
        newColumn = new DataColumn(p_GridviewToCopy.Columns[columnIndex].HeaderText, typeof(String));
        newColumn.Caption = p_GridviewToCopy.Columns[columnIndex].HeaderText;
        copiedTable.Columns.Add(newColumn);
    }

    //add rows
    for (int xx = 0; xx < p_GridviewToCopy.Rows.Count; xx++)
    {
        newRow = copiedTable.NewRow();
        for (int yy = 0; yy < p_GridviewToCopy.Columns.Count; yy++)
        {
                newRow.SetField(p_GridviewToCopy.Columns[yy].HeaderText, p_GridviewToCopy.Rows[xx].Cells[yy]);
        }
        copiedTable.Rows.Add(newRow);
    }
    returnCoppiedGridView.DataSource = copiedTable;
    returnCoppiedGridView.DataBind();
    return returnCoppiedGridView;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900