Member 12859772 Ответов: 1

Практическое руководство скопировать на другой элемент


<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" />


Что я уже пробовал:

Hi everyone. I have two gridview. When I selected checkbox I want to copy to gridview another gridview. How can I do this.

1 Ответов

Рейтинг:
0

haisol

Как насчет использования этой функции

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