Jun 18, 2011, 9:13 PM
db saving of GridPanel records re-ordering
HI techies,
I have a problem saving of gridpanel rows re-order in database.i using sqldatasource control to bind to store and for updating alos am using sqldatasource control.
When I clk on Up/Down arrows then I am able to re-ordering the rows. after click on the save button these order not updating into the database
Can anyone plzzz help. it is very very urgent to me.
here is code
I have a problem saving of gridpanel rows re-order in database.i using sqldatasource control to bind to store and for updating alos am using sqldatasource control.
When I clk on Up/Down arrows then I am able to re-ordering the rows. after click on the save button these order not updating into the database
Can anyone plzzz help. it is very very urgent to me.
here is code
<%@ Page Language="C#" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Ext.NET Example</title>
<script type="text/javascript">
function konda()
{
alert(Ext.encode(GridPanel1.getRowsValues(false)));
}
function MoveUpOrDown(command, grid, rowIndex, colIndex, propertyToSwap)
{
var newIndex = -1, store = grid.getStore();
if (command == 'MoveUp' && rowIndex > 0)
{
newIndex = rowIndex - 1;
}
else if (command == 'MoveDown' && rowIndex < store.data.items.length - 1)
{
newIndex = rowIndex + 1;
}
if (newIndex !== -1)
{
swap(store.data.items, rowIndex, newIndex, "Sort");
//We have to do the same if there is a snapshot in the store
if (store.snapshot && store.snapshot != store.data)
{
swap(store.snapshop.items, rowIndex, newIndex, "Sort");
}
grid.store.data.items[rowIndex].commit();
grid.store.data.items[newIndex].commit();
// var newRecord = store.getAt(newIndex);
// curRecord.commit();
// newRecord.commit();
return false;
}
return true;
}
function swap(array, oldIndex, newIndex, propertyToSwap)
{
var temp = array[oldIndex];
array[oldIndex] = array[newIndex];
array[newIndex] = temp;
temp = array[oldIndex].data[propertyToSwap];
array[oldIndex].data[propertyToSwap] = array[newIndex].data[propertyToSwap];
array[newIndex].data[propertyToSwap] = temp;
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=wizard;Data Source=DRAGRAN"
SelectCommand="select ID,Name, Description, Width,Height,Sort from tblWebAdPosition order by Sort asc "
UpdateCommand="update tblWebAdPosition set Name =@Name, Description=@Description, Width=@Width, Height=@Height,Sort=@Sort where ID=@ID">
<UpdateParameters>
<asp:Parameter Name="Name" DbType="String" />
<asp:Parameter Name="Description" DbType="String" />
<asp:Parameter Name="Width" DbType="Int32" />
<asp:Parameter Name="Height" DbType="Int32" />
<asp:Parameter Name="Sort" DbType="Int32" />
<asp:Parameter Name="ID" DbType="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<ext:Store ID="Store1" runat="server" DataSourceID="SqlDataSource1">
<Reader>
<%--<ext:ArrayReader>
<Fields>
<ext:RecordField Name="company" />
<ext:RecordField Name="price" Type="Float" />
<ext:RecordField Name="change" Type="Float" />
<ext:RecordField Name="pctChange" Type="Float" />
<ext:RecordField Name="lastChange" Type="Date" DateFormat="n/j h:ia" />
</Fields>
</ext:ArrayReader>--%>
<ext:JsonReader ReaderID="ID">
<Fields>
<ext:RecordField Name="ID">
</ext:RecordField>
<ext:RecordField Name="Name">
</ext:RecordField>
<ext:RecordField Name="Description">
</ext:RecordField>
<ext:RecordField Name="Width">
</ext:RecordField>
<ext:RecordField Name="Height">
</ext:RecordField>
<ext:RecordField Name="Sort">
</ext:RecordField>
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
<ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1" AutoHeight="true">
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:ImageCommandColumn>
<Commands>
<ext:ImageCommand Icon="ArrowUp" CommandName="MoveUp" />
<ext:ImageCommand Icon="ArrowDown" CommandName="MoveDown" />
</Commands>
</ext:ImageCommandColumn>
<ext:Column Header="Name" Width="160" Sortable="true" DataIndex="Name" />
<ext:Column Header="Description" Width="75" Sortable="true" DataIndex="Description">
</ext:Column>
<ext:Column Header="Width" Width="75" Sortable="true" DataIndex="Width" />
<ext:Column Header="Height" Width="75" Sortable="true" DataIndex="Height" />
<ext:Column Header="Sort" Width="75" Sortable="true" DataIndex="Sort" />
</Columns>
</ColumnModel>
<Listeners>
<Command Handler="if (command === 'MoveUp' || command === 'MoveDown') {
MoveUpOrDown(command, #{GridPanel1}, rowIndex, colIndex, 'Sort');
return false;
}
" />
</Listeners>
<BottomBar>
<ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="5" />
</BottomBar>
<%-- <Plugins>
<ext:GridFilters ID="GridFilters1" runat="server">
<Filters>
<ext:StringFilter DataIndex="SectionName" />
</Filters>
</ext:GridFilters>
</Plugins>--%>
</ext:GridPanel>
<ext:Button ID="Button1" runat="server" Text="Save">
<Listeners>
<Click Handler="#{GridPanel1}.save();" />
</Listeners>
</ext:Button>
</form>
</body>
</html>