I have a code that can Drag Rows from one grid o another one and now I want to access the columns in the second gridview and save it into the database.
how can I get the values of column[i]?!
What I have tried:
This is my code
$(function () {
var sourceCount = $("#gvSource").find('tr:not(tr:first-child)').length;
var destCount = $("#gvDest").find('tr:not(tr:first-child)').length - 1;
$(".drag_drop_grid").sortable({
items: 'tr:not(tr:first-child)',
cursor: 'crosshair',
connectWith: '.drag_drop_grid',
axis: 'y',
dropOnEmpty: true,
receive: function (e, ui) {
if (e.target.id == 'gvDest') {
destCount++;
sourceCount--;
$('#hfSourceRowsCount').val(sourceCount);
$('#hfDestRowsCount').val(destCount);
}
else if (e.target.id == 'gvSource') {
destCount--;
sourceCount++;
$('#hfSourceRowsCount').val(sourceCount);
$('#hfDestRowsCount').val(destCount);
}
$(this).find("tbody").append(ui.item);
}
});
$("[id*=gvDest] tr:not(tr:first-child)").remove();
});
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
System.Data.DataTable dt = new System.Data.DataTable();
dt.Columns.AddRange(new System.Data.DataColumn[2] { new System.Data.DataColumn("Item"), new System.Data.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();
}
}
protected void Count(object sender, EventArgs e)
{
int rowsgvSource = Convert.ToInt32(hfSourceRowsCount.Value);
int rowsgvDest = Convert.ToInt32(hfDestRowsCount.Value);
ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('Source Count: " + rowsgvSource + "'); alert('Destination Count: " + rowsgvDest + "');", true);
}