Hi!!
I was reading the post about "Drag and Drop Rows from Source GridView to Destination GridView in ASP.Net using jQuery" from Mudassar and everything worked. I never worked with jquery but it seems powerfull! But now i have a problem that maybe someone could help me! I'm creating asp.net repeaters instead gridview and jquery works fine! The problem is that i'm creating these repeaters based on the count items of a list, for example 3 repeaters with same datasource (these repeaters are my class GrdDest). When a drag some row from a repeater (GrdSrc) into a destination repeater this row is reflected in all of the destination repeaters instead of the one that i choose.
So i wanted to know if there's some jquery code that can prevent this behavior.
Best regards,
Boyzik
The code is below:
client side:
<script type="text/javascript">
$(function () {
$(".GridSrc, .GridDest").sortable({
items: 'tr:not(tr:first-child)',
connectWith: '.GridSrc, .GridDest',
receive: function (e, ui) {
$(this).find("tbody").append(ui.item);
}
});
$("[id*=GridDest] tr:not(tr:first-child)").remove();
// $('div').each(function(index) {
// alert(index + ': ' + $(this).text()); });
});
<asp:Panel ID="Panel1" runat="server">
<table width="100%">
<tr>
<td>
<div style="overflow-y: scroll; width: 50%; height:180px; border:solid 2px #ccc;">
<asp:Repeater ID="tblFilial" runat="server">
</asp:Repeater>
<div id="dvRptsDinamicos" runat="server" class="GridDest">
</div>
</div>
</td>
<td>
<div style="overflow-y: scroll; width: 50%; height:180px; border:solid 2px #ccc;">
<div id="dvRptPendentes" runat="server" class="GridSrc">
</div>
</div>
</td>
</tr>
</table>
</asp:Panel>
Code Behind:
public class RepeaterTemplateTecnicos : System.Web.UI.ITemplate
{
ListItemType templateType;
public RepeaterTemplateTecnicos(ListItemType type)
{
templateType = type;
}
public RepeaterTemplateTecnicos() { }
public void InstantiateIn(Control container)
{
string aa = "gg";
PlaceHolder ph = new PlaceHolder();
Label item1 = new Label();
Label item2 = new Label();
item1.ID = "item1";
item2.ID = "item2";
switch (templateType)
{
case ListItemType.Header:
ph.Controls.Add(new LiteralControl("<table>" +
"<thead><tr><th colspan='2' align='center'> " + aa + "</th></tr></thead>" +
"<tr><td><b>OrdemServico</b></td>" +
"<td><b>Tecnico</b></td></tr>"));
break;
case ListItemType.Item:
ph.Controls.Add(new LiteralControl("<tr><td>"));
ph.Controls.Add(item1);
ph.Controls.Add(new LiteralControl("</td><td>"));
ph.Controls.Add(item2);
ph.Controls.Add(new LiteralControl("</td></tr>"));
ph.DataBinding += new EventHandler(Item_DataBinding);
break;
case ListItemType.AlternatingItem:
ph.Controls.Add(new LiteralControl("<tr><td>"));
ph.Controls.Add(item1);
ph.Controls.Add(new LiteralControl("</td><td>"));
ph.Controls.Add(item2);
ph.Controls.Add(new LiteralControl("</td></tr>"));
ph.DataBinding += new EventHandler(Item_DataBinding);
break;
case ListItemType.Footer:
ph.Controls.Add(new LiteralControl("</table>"));
break;
}
container.Controls.Add(ph);
}
static void Item_DataBinding(object sender, System.EventArgs e)
{
PlaceHolder ph = (PlaceHolder)sender;
RepeaterItem ri = (RepeaterItem)ph.NamingContainer;
String item1Value = (String)DataBinder.Eval(ri.DataItem, "OrdemServico");
String item2Value = (String)DataBinder.Eval(ri.DataItem, "Tecnico");
((Label)ph.FindControl("item1")).Text = item1Value.ToString();
((Label)ph.FindControl("item2")).Text = item2Value;
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("OrdemServico", Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("Tecnico", Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("Cliente", Type.GetType("System.String")));
dt.Columns.Add(new DataColumn("Data", Type.GetType("System.DateTime")));
DataRow dr = dt.NewRow();
dr["OrdemServico"] = "000000001";
dr["Tecnico"] = "Bruno Fonseca";
dr["Cliente"] = "Syone";
dr["Data"] = "28/11/2011";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["OrdemServico"] = "000000002";
dr["Tecnico"] = "Bruno Silva";
dr["Cliente"] = "Syone 2";
dr["Data"] = "01/10/2010";
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["OrdemServico"] = "000000003";
dr["Tecnico"] = "João Pires";
dr["Cliente"] = "Syone 4";
dr["Data"] = "18/06/2010";
dt.Rows.Add(dr);
//rptOrdensServico.DataSource = dt;
//rptOrdensServico.DataBind();
Repeater rptPendente = new Repeater();
rptPendente.HeaderTemplate = new RepeaterTemplateTecnicos(ListItemType.Header);
rptPendente.ItemTemplate = new RepeaterTemplateTecnicos(ListItemType.Item);
rptPendente.AlternatingItemTemplate =
new RepeaterTemplateTecnicos(ListItemType.AlternatingItem);
rptPendente.FooterTemplate = new RepeaterTemplateTecnicos(ListItemType.Footer);
rptPendente.DataSource = dt;
rptPendente.DataBind();
dvRptPendentes.Controls.Add(rptPendente);
List<string> tecnicos = new List<string>();
tecnicos.Add("T1");
tecnicos.Add("T3");
tecnicos.Add("T2");
foreach (var item in tecnicos)
{
Repeater rpt = new Repeater();
rpt.HeaderTemplate = new RepeaterTemplateTecnicos(ListItemType.Header);
rpt.ItemTemplate = new RepeaterTemplateTecnicos(ListItemType.Item);
rpt.AlternatingItemTemplate =
new RepeaterTemplateTecnicos(ListItemType.AlternatingItem);
rpt.FooterTemplate = new RepeaterTemplateTecnicos(ListItemType.Footer);
dt.Clear();
rpt.DataSource = dt;
rpt.DataBind();
rpt.Controls.Add(new LiteralControl("<br/>"));
//tblFilial.Controls.Add(new LiteralControl("<table> <tr></tr> </table>"));
tblFilial.Controls.Add(rpt);
dvRptsDinamicos.Controls.Add(rpt);
}
}
}