move up and down gridview with jQuery and Save
Hi
i have found solution for move up and down rows in my gridview in asp.net... with jQuery but how save the new sorting??
the name of gridview is gridFeaturedPostImages
- <asp:TemplateField HeaderText="Up" ItemStyle-VerticalAlign="middle" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="25">
<ItemTemplate>
<asp:HyperLink ID="HyperLink2" class="up" runat="server" OnClick="#" ImageUrl="~/User controls/FeaturedPostsRotator/images/up.png" ></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Down" ItemStyle-VerticalAlign="middle" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="25">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" class="down" runat="server" OnClick="#" ImageUrl="~/User controls/FeaturedPostsRotator/images/down.png" ></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
and the code of jquery is
- <script type="text/javascript">
$(document).ready(function(){
$(".up, .down").click(function() {
// get parent tr
var $row = $(this).parents('tr:first');
var $link = $(this);
// count all tr
var count = $('table tr').length;
// if tr isn't the first
if($row.index() !== 0) {
// if direction is up and there is a tr above
if($link.hasClass('up') && $row.index() > 1) {
$row.insertBefore($row.prev());
}
// if direction is down and there is a tr below
else if($link.hasClass('down') && $row.index() < count - 1) {
$row.insertAfter($row.next());
/* for (int i=0;i< $gridFeaturedPostImages.Rows.Count;i++)
{
$gridFeaturedPostImages.UpdateRow(i, true);
$gridFeaturedPostImages.DataBind();
}*/
}
var inputs = $("#myTable").find("tr").find("input");
// store each rows id in an array - this will be in the correct order
var ids = [];
inputs.each(function(){
ids.push($(this).val());
});
}
});
});
</script>
thank you very much..
fabry