Jul 23, 2010, 6:35 AM
When i click delete button it will delete data in database by using linq2sql datasource
using System.Text;
using System.Data.Linq;
using WebApplication4;
public class FiltersTestData
{
public static List<tblOrder> Data
{
get
{
DataClasses1DataContext obj = new DataClasses1DataContext();
return obj.tblOrders.ToList();
}
}
}
...........................................................................................................................
protected void Store1_RefreshData(object sender, StoreRefreshDataEventArgs e)
{
List<WebApplication4.tblOrder> data = FiltersTestData.Data;
string s = e.Parameters[this.GridFilters1.ParamPrefix];
//or with hardcoding - string s = e.Parameters["gridfilters"];;
//-- start filtering ------------------------------------------------------------
if (!string.IsNullOrEmpty(s))
{
FilterConditions fc = new FilterConditions(s);
foreach (FilterCondition condition in fc.Conditions)
{
Comparison comparison = condition.Comparison;
string field = condition.Name;
FilterType type = condition.FilterType;
object value;
switch(condition.FilterType)
{
case FilterType.Boolean:
value = condition.ValueAsBoolean;
break;
case FilterType.Date:
value = condition.ValueAsDate;
break;
case FilterType.List:
value = condition.ValuesList;
break;
case FilterType.Numeric:
if (data.Count > 0 && data[0].GetType().GetProperty(field).PropertyType == typeof(int))
{
value = condition.ValueAsInt;
}
else
{
value = condition.ValueAsDouble;
}
break;
case FilterType.String:
value = condition.Value;
break;
default:
throw new ArgumentOutOfRangeException();
}
data.RemoveAll(
item =>
{
object oValue = item.GetType().GetProperty(field).GetValue(item, null);
IComparable cItem = oValue as IComparable;
switch (comparison)
{
case Comparison.Eq:
switch(type)
{
case FilterType.List:
return !(value as ReadOnlyCollection<string>).Contains(oValue.ToString());
case FilterType.String:
return !oValue.ToString().StartsWith(value.ToString());
default:
return !cItem.Equals(value);
}
case Comparison.Gt:
return cItem.CompareTo(value) < 1;
case Comparison.Lt:
return cItem.CompareTo(value) > -1;
default:
throw new ArgumentOutOfRangeException();
}
}
);
}
}
//-- end filtering ------------------------------------------------------------
//-- start paging ------------------------------------------------------------
var limit = e.Limit;
if ((e.Start + e.Limit) > data.Count)
{
limit = data.Count - e.Start;
}
List<WebApplication4.tblOrder> rangeData = (e.Start < 0 || limit < 0) ? data : data.GetRange(e.Start, limit);
//-- end paging ------------------------------------------------------------
e.Total = data.Count;
this.Store1.DataSource = rangeData;
}
........................................................................................................................................................
<div>
<ext:Store runat="server" ID="Store1" RemoteSort="true" OnRefreshData="Store1_RefreshData">
<Proxy>
<ext:PageProxy />
</Proxy>
<Reader>
<ext:JsonReader IDProperty="OrderID">
<Fields>
<ext:RecordField Name="OrderID" />
<ext:RecordField Name="OrderPlacedDate" />
<ext:RecordField Name="OrderAmount" />
<ext:RecordField Name="OrderState" />
<ext:RecordField Name="OrderProcessedDate" />
<ext:RecordField Name="OrderShippedDate" />
<ext:RecordField Name="UserID" />
</Fields>
</ext:JsonReader>
</Reader>
<BaseParams>
<ext:Parameter Name="start" Value="0" Mode="Raw" />
<ext:Parameter Name="limit" Value="10" Mode="Raw" />
<ext:Parameter Name="sort" Value="" />
<ext:Parameter Name="dir" Value="" />
</BaseParams>
<SortInfo Field="OrderID" Direction="ASC" />
</ext:Store>
<ext:Panel
ID="pnlSouth"
runat="server"
Title="OrderDtails"
Height="222px"
Icon="Basket"
Layout="Fit" style="margin-bottom: 0">
<Items>
<ext:GridPanel
runat="server"
ID="GridPanel1"
Border="false"
StoreID="Store1">
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column DataIndex="OrderID" Header="OrderID" >
</ext:Column>
<ext:Column DataIndex="OrderPlacedDate" Header="OrderPlacedDate">
</ext:Column>
<ext:Column DataIndex="OrderAmount" Header="OrderAmount">
</ext:Column>
<ext:Column DataIndex="OrderState" Header="OrderState">
<Editor>
<ext:ComboBox ID="ComboBox1" runat="server">
<Template ID="ctl75"></Template>
<Items>
<ext:ListItem Value="In-Process" Text="In-Process" />
<ext:ListItem Value="Shipped" Text="Shipped"/>
<ext:ListItem Value="Delivered" Text="Delivered" />
<ext:ListItem Value="Cancelled" Text="Cancelled" />
</Items>
</ext:ComboBox>
</Editor>
</ext:Column>
<ext:Column DataIndex="OrderProcessedDate" Header="OrderProcessedDate">
</ext:Column>
<ext:Column DataIndex="OrderShippedDate" Header="OrderShippedDate">
</ext:Column>
<ext:Column DataIndex="UserID" Header="UserID">
</ext:Column>
</Columns>
</ColumnModel>
<LoadMask ShowMask="true" />
<Plugins>
<ext:GridFilters runat="server" ID="GridFilters1">
<Filters>
<ext:NumericFilter DataIndex="OrderID" />
<ext:DateFilter DataIndex="OrderPlacedDate">
</ext:DateFilter>
<ext:NumericFilter DataIndex="OrderAmount" />
<ext:StringFilter DataIndex="OrderState" />
<ext:DateFilter DataIndex="OrderProcessedDate">
</ext:DateFilter>
<ext:DateFilter DataIndex="OrderShippedDate">
</ext:DateFilter>
<ext:DateFilter DataIndex="UserID">
</ext:DateFilter>
</Filters>
</ext:GridFilters>
</Plugins>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel2" runat="server" SingleSelect="true">
<Listeners>
<RowSelect Handler="if (#{pnlSouth}.isVisible()) {#{Store2}.reload();}" Buffer="250" />
</Listeners>
</ext:RowSelectionModel>
</SelectionModel>
<BottomBar>
<ext:PagingToolbar
ID="PagingToolBar1"
runat="server"
PageSize="2"
StoreID="Store1"
DisplayInfo="true"
/>
</BottomBar>
<SaveMask ShowMask="true" />
<LoadMask ShowMask="true" />
</ext:GridPanel>
</Items>
<Buttons>
<ext:Button ID="btnSave" runat="server" Text="Save" Icon="Disk">
<Listeners>
<Click Handler="#{GridPanel1}.save();" />
</Listeners>
</ext:Button>
<ext:Button ID="btnDelete" runat="server" Text="Delete selected records" Icon="Delete" >
<Listeners>
<Click Handler="#{GridPanel1}.deleteSelected();" />
</Listeners>
</ext:Button>
<ext:Button ID="btnInsert" runat="server" Text="Insert" Icon="Add">
<Listeners>
<Click Handler="#{GridPanel1}.insertRecord(0, {});#{GridPanel1}.getView().focusRow(0);#{GridPanel1}.startEditing(0,0);" />
</Listeners>
</ext:Button>
<ext:Button ID="btnRefresh" runat="server" Text="Refresh" Icon="ArrowRefresh">
<Listeners>
<Click Handler="#{GridPanel1}.reload();" />
</Listeners>
</ext:Button>
<ext:Button ID="btnEmulError" runat="server" Text="Refresh with Emulated error" Icon="Exclamation">
<Listeners>
<Click Handler="#{GridPanel1}.reload({params:{EmulateError: 1}});" />
</Listeners>
</ext:Button>
</Buttons>
</ext:Panel>
</div>
.................................................. .................................................. ........[MY DOUBT]<ext:Button ID="btnDelete" runat="server" Text="Delete selected records" Icon="Delete" >
<Listeners>
<Click Handler="#{GridPanel1}.deleteSelected();" />
</Listeners>
</ext:Button>
WHEN I CLICK DELETE BUTTON IT WILL DELETE DATA IN DATABASE BY USING LINQ2SQL DATASOURCE
Last edited by geoffrey.mcgill; Jul 29, 2010 at 9:23 PM.
Reason: please use [code] tags