Click here to Skip to main content
15,911,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi ,
I have two gridview i want drag and drop rows from one gridview to another griedview
in client side.

Please solve my proble asap

Thanks
Posted
Comments
Hemant Singh Rautela 13-Jun-13 3:54am    
For this you have to use jquery..

IN Sample.aspx
=================
XML
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
    <link rel="Stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css" />
    <script type="text/javascript">
        $(function () {
            $(".drag_drop_grid").sortable({
                items: 'tr:not(tr:first-child)',
                cursor: 'crosshair',
                connectWith: '.drag_drop_grid',
                axis: 'y',
                dropOnEmpty: true,
                receive: function (e, ui) {
                    $(this).find("tbody").append(ui.item);
                }
            });
            $("[id*=gvDest] tr:not(tr:first-child)").remove();
        });
    </script>
    <%--<style type="text/css">
    .GridSrc td
    {
        background-color: #A1DCF2;
        color: black;
        font-size: 10pt;
        font-family:Arial;
        line-height: 200%;
        cursor: pointer;
        width:100px
    }
    .GridSrc th
    {
        background-color: #3AC0F2;
        color: White;
        font-family:Arial;
        font-size: 10pt;
        line-height: 200%;
        width:100px;
    }
    .GridDest td
    {
        background-color: #eee !important;
        color: black;
        font-family:Arial;
        font-size: 10pt;
        line-height: 200%;
        cursor: pointer;
        width:100px
    }
    .GridDest th
    {
        background-color: #6C6C6C !important;
        color: White;
        font-family:Arial;
        font-size: 10pt;
        line-height: 200%;
        width:100px
    }
</style>--%>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <asp:GridView ID="gvSource" runat="server" CssClass="drag_drop_grid GridSrc" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:BoundField DataField="CountryId" HeaderText="CountryId" />
                    <asp:BoundField DataField="CountryName" HeaderText="CountryName" />
                </Columns>
                <EditRowStyle BackColor="#2461BF" />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#EFF3FB" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#F5F7FB" />
                <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                <SortedDescendingCellStyle BackColor="#E9EBEF" />
                <SortedDescendingHeaderStyle BackColor="#4870BE" />
            </asp:GridView>
           <br />
            <asp:GridView ID="gvDest" runat="server" CssClass="drag_drop_grid GridDest" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">
                <Columns>
                    <asp:BoundField DataField="CountryId" HeaderText="CountryId" />
                    <asp:BoundField DataField="CountryName" HeaderText="CountryName" />
                </Columns>
                <FooterStyle BackColor="#CCCC99" ForeColor="Black" />
                <HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
                <SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
                <SortedAscendingCellStyle BackColor="#F7F7F7" />
                <SortedAscendingHeaderStyle BackColor="#4B4B4B" />
                <SortedDescendingCellStyle BackColor="#E5E5E5" />
                <SortedDescendingHeaderStyle BackColor="#242121" />
            </asp:GridView>
        </div>
    </form>
</body>



IN Sample.aspx.cs
====================
C#
if (!Page.IsPostBack)
       {
           con.Open();
           cmd = new SqlCommand();
           cmd.Connection = con;
           cmd.CommandText = "select * from Country";
           cmd.ExecuteNonQuery();
           da = new SqlDataAdapter(cmd);
           dt = new DataTable();
           da.Fill(dt);

           //DataTable dt = new DataTable();
           //dt.Columns.AddRange(new DataColumn[2] { new DataColumn("Item"), new DataColumn("Price") });
           //dt.Rows.Add("Shirt", 450);
           //dt.Rows.Add("Jeans", 3200);
           //dt.Rows.Add("Trousers", 1900);
           //dt.Rows.Add("Tie", 185);
           //dt.Rows.Add("Cap", 100);
           //dt.Rows.Add("Hat", 120);
           //dt.Rows.Add("Scarf", 290);
           //dt.Rows.Add("Belt", 150);
           gvSource.UseAccessibleHeader = true;
           gvSource.DataSource = dt;
           gvSource.DataBind();

           dt.Rows.Clear();
           dt.Rows.Add();
           gvDest.DataSource = dt;
           gvDest.DataBind();
       }
 
Share this answer
 
Comments
prashantttt 15-Sep-14 4:07am    
Is There Any Way to Debug this drag drop proccesss...?

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