|
The class is described below allows the use of grouping, sorting, pagind, external filters with DevExpress ASPxGridView, but using data access method as standart ASP.NET ObjectDataSource
Initialization of data binding in ASPxGridView looks like this:
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (!IsPostBack)
{
DXExtensions.Data.DXObjectDataSource dxOdsAddress = new DXExtensions.Data.DXObjectDataSource();
dxOdsAddress.PageSize = gvAddress.SettingsPager.PageSize;
dxOdsAddress.KeyFeildName = gvAddress.KeyFieldName;
dxOdsAddress.DataType = typeof(DomainModel.AddressEntities.Address);
dxOdsAddress.Request_DataSource += new EventHandler<DXExtensions.Data.DXObjectDataSource.PagingEventArgs>(dxodsAddress_RequestDataSource);
dxOdsAddress.Request_TotalRowsCount += new EventHandler(dxodsAddress_RequestTotalRowsCount);
dxOdsAddress.Request_GroupInfo += new EventHandler<DXExtensions.Data.DXObjectDataSource.GroupingEventArgs>(dxodsAddress_RequestGroupInfo);
Session["dxOdsAddress"] = dxOdsAddress;
}
gvAddress.DataSource = Session["dxOdsAddress"] as DXExtensions.Data.DXObjectDataSource;
}
This class is based on the example described here: A possible implementation of IListServer interface to achieve Server Mode functionality
DXObjectDataSource class:
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using DevExpress.Data;
namespace DXExtensions.Data
{
public class DXObjectDataSource : IListServer, ITypedList
{
#region New
#region Exceptions
public class DataSourceNotBindedException : Exception
{
public DataSourceNotBindedException()
: base()
{}
}
public class DataSourceSubcriberNotFoundException : Exception
{
public DataSourceSubcriberNotFoundException()
: base()
{ }
}
public class TotalRowsCountNotBindedException : Exception
{
public TotalRowsCountNotBindedException()
: base()
{ }
}
public class TotalRowsCountSubscriberNotFoundException : Exception
{
public TotalRowsCountSubscriberNotFoundException()
: base()
{ }
}
public class UnexpectedLogicWayException : Exception
{
public UnexpectedLogicWayException()
: base()
{ }
}
#endregion
#region PublicConnectors
public class PagingEventArgs : EventArgs
{
private int _StartRowIndex;
public int StartRowIndex
{
get
{
return _StartRowIndex;
}
set
{
_StartRowIndex = value;
}
}
private int _RowsCount;
public int RowsCount
{
get
{
return _RowsCount;
}
set
{
_RowsCount = value;
}
}
private ICollection<ServerModeOrderDescriptor> _SortInfo;
public ICollection<ServerModeOrderDescriptor> SortInfo
{
get
{
return _SortInfo;
}
set
{
_SortInfo = value;
}
}
}
public class GroupingEventArgs : EventArgs
{
ListSourceGroupInfo _ParentGroupInfo;
public ListSourceGroupInfo ParentGroupInfo
{
get
{
return _ParentGroupInfo;
}
set
{
_ParentGroupInfo = value;
}
}
List<ListSourceGroupInfo> _GroupInfo;
public List<ListSourceGroupInfo> GroupInfo
{
get
{
return _GroupInfo;
}
set
{
_GroupInfo = value;
}
}
}
public event EventHandler<PagingEventArgs> Request_DataSource;
public event EventHandler Request_TotalRowsCount;
public event EventHandler<GroupingEventArgs> Request_GroupInfo;
public void RefreshForNewFilters()
{
_ActualizeDataSource_StartIndex = 0;
_DataSource = null;
}
#endregion
#region Propertyes
private Type _DataType;
public Type DataType
{
get
{
return _DataType;
}
set
{
_DataType = value;
}
}
private IList _DataSource;
public IList DataSource
{
get
{
return _DataSource;
}
set
{
_DataSource = value;
}
}
private Int32 _TotalRowsCount = -1;
public Int32 TotalRowsCount
{
get
{
return _TotalRowsCount;
}
set
{
_TotalRowsCount = value;
}
}
private Int32 _PageSize;
public Int32 PageSize
{
get
{
return _PageSize;
}
set
{
_PageSize = value;
}
}
private string _KeyFeildName;
public string KeyFeildName
{
get
{
return _KeyFeildName;
}
set
{
_KeyFeildName = value;
}
}
private ICollection<ServerModeOrderDescriptor> _SortInfo;
#endregion
bool IsZeroIndexActual;
private int _ActualizeDataSource_StartIndex;
protected int ActualizeDataSource(int index)
{
bool isDataSourceActual = true;
if (_DataSource == null)
{
isDataSourceActual = false;
}
else
{
if ((index == 0) && (!IsZeroIndexActual))
{
return 0;
}
else
{
if ((index >= _ActualizeDataSource_StartIndex + _PageSize) || ((index < _ActualizeDataSource_StartIndex)))
{
isDataSourceActual = false;
}
}
}
if (!isDataSourceActual)
{
_ActualizeDataSource_StartIndex = index;
PagingEventArgs pea = new PagingEventArgs();
pea.StartRowIndex = index;
pea.RowsCount = _PageSize;
pea.SortInfo = _SortInfo;
if (Request_DataSource != null)
{
Request_DataSource(this, pea);
if (_DataSource == null)
{
throw new DataSourceNotBindedException();
}
}
else
{
throw new DataSourceSubcriberNotFoundException();
}
}
int ret = index - _ActualizeDataSource_StartIndex;
if (ret < 0)
{
ret = 0;
}
return ret;
}
#endregion
#region IList Enabled
object IList.this[int index]
{
get
{
int actualRecordIndex = ActualizeDataSource(index);
if (_DataSource != null)
{
return _DataSource[actualRecordIndex];
}
return null;
}
set
{
throw new NotImplementedException();
}
}
#endregion
#region ICollection Enabled
int ICollection.Count
{
get
{
return _TotalRowsCount;
}
}
#endregion
#region ITypedList Enabled
PropertyDescriptorCollection ITypedList.GetItemProperties(PropertyDescriptor[] listAccessors)
{
IsZeroIndexActual = false;
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(_DataType);
if (Request_TotalRowsCount != null)
{
Request_TotalRowsCount(this, new EventArgs());
if (_TotalRowsCount < 0)
{
throw new TotalRowsCountNotBindedException();
}
}
else
{
throw new TotalRowsCountSubscriberNotFoundException();
}
return pdc;
}
#endregion
#region DevExpress.Data.IListServer Enabled
void IListServer.Apply
(
DevExpress.Data.Filtering.CriteriaOperator filterCriteria,
ICollection<ServerModeOrderDescriptor> sortInfo,
int groupCount,
ICollection<ServerModeSummaryDescriptor> groupSummaryInfo,
ICollection<ServerModeSummaryDescriptor> totalSummaryInfo
)
{
if ((_SortInfo != sortInfo))
{
_ActualizeDataSource_StartIndex = 0;
_DataSource = null;
_SortInfo = sortInfo;
}
IsZeroIndexActual = true;
}
object IListServer.GetRowKey(int index)
{
int actualRecordIndex = ActualizeDataSource(index);
if (_DataSource != null)
{
System.Reflection.PropertyInfo pi = _DataType.GetProperty(KeyFeildName);
System.Reflection.MethodInfo mi = pi.GetGetMethod();
object recordObject = _DataSource[actualRecordIndex];
object ret = mi.Invoke(recordObject, null);
return ret;
}
else
{
throw new UnexpectedLogicWayException();
}
}
List<ListSourceGroupInfo> IListServer.GetGroupInfo(DevExpress.Data.ListSourceGroupInfo groupInfo)
{
GroupingEventArgs gea = new GroupingEventArgs();
gea.ParentGroupInfo = groupInfo;
if (Request_GroupInfo != null)
{
Request_GroupInfo(this, gea);
return gea.GroupInfo;
}
else
{
throw new NotImplementedException();
}
}
#endregion
#region Disabled
#region IList Disabled
int IList.Add(object value)
{
throw new NotImplementedException();
}
void IList.Clear()
{
throw new NotImplementedException();
}
bool IList.Contains(object value)
{
throw new NotImplementedException();
}
int IList.IndexOf(object value)
{
throw new NotImplementedException();
}
void IList.Insert(int index, object value)
{
throw new NotImplementedException();
}
bool IList.IsFixedSize
{
get { throw new NotImplementedException(); }
}
bool IList.IsReadOnly
{
get { throw new NotImplementedException(); }
}
void IList.Remove(object value)
{
throw new NotImplementedException();
}
void IList.RemoveAt(int index)
{
throw new NotImplementedException();
}
#endregion
#region ICollection Disabled
void ICollection.CopyTo(Array array, int index)
{
throw new NotImplementedException();
}
bool ICollection.IsSynchronized
{
get { throw new NotImplementedException(); }
}
object ICollection.SyncRoot
{
get { throw new NotImplementedException(); }
}
#endregion
#region IEnumerable Disabled
IEnumerator IEnumerable.GetEnumerator()
{
throw new NotImplementedException();
}
#endregion
#region ITypedList Disabled
string ITypedList.GetListName(PropertyDescriptor[] listAccessors)
{
return "";
}
#endregion
#region DevExpress.Data.IListServer Disabled
event EventHandler<ServerModeExceptionThrownEventArgs> IListServer.ExceptionThrown
{
add { throw new NotImplementedException(); }
remove { throw new NotImplementedException(); }
}
event EventHandler<ServerModeInconsistencyDetectedEventArgs> IListServer.InconsistencyDetected
{
add { throw new NotImplementedException(); }
remove { throw new NotImplementedException(); }
}
IList IListServer.GetAllFilteredAndSortedRows()
{
throw new NotImplementedException();
}
int IListServer.GetRowIndexByKey(object key)
{
throw new NotImplementedException();
}
int IListServer.FindIncremental
(
DevExpress.Data.Filtering.CriteriaOperator expression,
string value,
int startIndex,
bool searchUp,
bool ignoreStartRow,
bool allowLoop
)
{
throw new NotImplementedException();
}
Dictionary<object, object> IListServer.GetTotalSummary()
{
throw new NotImplementedException();
}
object[] IListServer.GetUniqueColumnValues(DevExpress.Data.Filtering.CriteriaOperator expression, int maxCount,
bool includeFilteredOut)
{
throw new NotImplementedException();
}
int IListServer.LocateByValue(DevExpress.Data.Filtering.CriteriaOperator expression, object value, int
startIndex, bool searchUp)
{
throw new NotImplementedException();
}
void IListServer.Refresh()
{
throw new NotImplementedException();
}
#endregion
#endregion
}
}
|
|
|
|
|
Thanks Trongood,
There are two examples, that Vest from DevExpress support team has made that help also:
http://www.devexpress.com/example=E2672 -- Bind a grid to a ObjectDataSource with EnablePaging
and the last version of the sample:
http://www.devexpress.com/example=E166 -- A possible implementation of IListServer interface to achieve Server Mode functionality
was changed to support Sorting feature using LINQ (because LINQ expressions are easier to understand).
Thanks.
-Mehul Harry
|
|
|
|
|
Hi all, I am still new to web base programming. I have a redio button list and I am currently setting autopostback to true. But it blink the page, when change optins, I don't want the trip to server when I am not doing anything with the server. I wanted to use javascript to do the work for me.
Since I have never used it before having very dificult to use it. Lets Say Yes and No two optins. if user slect No it should do something and same for Yes option.
please help.
|
|
|
|
|
you would set autopostback to false. that stops the server trip.
Put your "do something" code as follows
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
Programming is a race between programmers trying to build bigger and better idiot proof programs, and the universe trying to build bigger and better idiots, so far... the universe is winning.
|
|
|
|
|
I alredy have something like this. but when I change my selection the page blink which I am trying to avoid. Just use javascript to do that so it will not go through server.
|
|
|
|
|
you said you had autopostback set to true. this must be set to false to stop the postback when you select a different button
Programming is a race between programmers trying to build bigger and better idiot proof programs, and the universe trying to build bigger and better idiots, so far... the universe is winning.
|
|
|
|
|
If I set autopost back to false then it is not catching the even when I change the selection from yes to No radio button.
|
|
|
|
|
In case of Auto postback false selected index change will not fire.
|
|
|
|
|
this is exactly what is happening. it is not firing the event when I change No to Yes on radio button options
All I want is that when the option is changed show two textboxes or not.
thanks
|
|
|
|
|
|
I have an ongoing debate with a co-worker about the merit of using server controls or code-behind for data, and I thought I'd post here for other people's opinions. I use SqlDataSources bound to controls, whereas he puts labels on the page and does everything in the code. (Oh, and I use stored procedures and not text commands, which I feel suffices for a DAL in small apps, so let's skip that argument.) I like it because it seems cleaner, faster, more concise, and gives access to the control events so work can be done at the appropriate time. Which do you prefer and why?
|
|
|
|
|
Using controls such as SqlDataSource is faster in some respects, however, it does not suffice as a true DAL, not even with stored procs. (Its an argument you will loose 9 out of 10 time). This method binds the presentation to data much too strongly for me. You should be able to build the application so each layer is independent.
I would say you are both right to a certain extent. The co-worker who is building everything by hand is going too far. DataBinding and templates can be used quite effectively. Separating the presentation and data, such as in a MVC or MVVM pattern gives much more flexibility and code reuse.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
|
Are this labels put on the form only once at the beggining of the page "lifecycle"? If yes - then declarative way would be better for traffic. Because each change of the page, which occurs in OnLoad() method is added to ViewState and travels to client with html page. If labels will be defined in .aspx then they will be created on Init() step and there will no additional ViewState data
|
|
|
|
|
does anybody use pdfbox? It is built into an application that I just inherited and suddenly has an Index was outside the bounds of the array. error. Now I do know what that means generally, however the debugger does not show me where its screwing up as it is withing pdfbox itself not part of the application code in and of itself. Its on a line call that has worked for over a year. No code has been updated, no servers have been updated(in regards to this app)
The application as a whole goes to a outside party website and pulls down a pdf file, that part works fine. It then used pdfbox to strip particular text out of that pdf file and puts that into a database. The text strip is where things have suddenly gone wonky.
My only thought so far is that the format of the pdf has been changed somehow but I cant tell where and again, its third party as well. So if anybody uses this particular tool and has had this issue in any way, a little hint of the right direction would be helpful.
Programming is a race between programmers trying to build bigger and better idiot proof programs, and the universe trying to build bigger and better idiots, so far... the universe is winning.
|
|
|
|
|
Hello,
I have a gridview, grid1 on the page which loads using the SqlDataSource, all the code is on the same page, the connection string, insertcommand etc. Everything is good and results display.
now, I have given the users the option to search. I want to bind the search results to the same grid1, the results would look the same except filtered on search criteria. When I try to use the same sql connection it comes back with WebControls.SqlDataSource and sqlclient.sqlconnection conversion issue. Is there a way to bind my search results to this grid as well?
Thanks!
|
|
|
|
|
Just used the selectcommand with the new sql select statement and bound the values. it worked well!
|
|
|
|
|
Dear All,
How can i clear the textboxes ofter a postback. I tried it with code below, but it doesn't work:
ViewData.ModelState.Remove("txtPassword");
Thanks in advance.
|
|
|
|
|
ViewData.ModelState.Clear(); ?
Sorry I can't test this, I'm in the middle of and installation at the mo'.
|
|
|
|
|
Hi Keith,
Thanks for your response.
But unfortunately it does'nt work.
|
|
|
|
|
|
Why don't you try setting that text box to empty something like -- txtBoxPassword.Text = "";
|
|
|
|
|
Hi all,
Does SiteMapNode property 'Roles' must provide for each Node those contain childNode ?
Because of if I do not add 'Roles' at SiteMapNode and set securityTrimmingEnabled="true" at webconfig.
Some SiteMapNodes those have childNode are not showing in menu.
Is there any way to show menu without provide 'Roles' to each SiteMapNode and just show menu as Admin user have defined Access rule for particular Role?
My purpose is when admin user create new Role and Access rule I don't want to manually add that new Role in sitemap file.
Thanks to all
|
|
|
|
|
while Redirect the page, Page_Load is not calling after hosting the application to IIS. when using the visual studio is calling ... i made like these..
Base class which has inherit Page
public partial class BasePage: Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Our page Inherit BasePage
public partial class MainPage : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Now calling from Another page
Response.Redirect(MainPage.aspx)
The Mainpage calss Page_Load is calling whilw running Visualstudio app. But after hosting to the IIS The Page_Load is not called
Please help me
Thanks
|
|
|
|
|
Something needs to trigger for this redirect to take place. Maybe you can have a javascript that this code inside page_load? Hope this makes sense.
|
|
|
|