var pagesize = Convert.ToInt32(ConfigurationManager.AppSettings["PageSize"]);
result = result.Skip(pagesize * currentPage).Take(pagesize).ToList();
Monday, May 26, 2014
LINQ ORDER BY EXPRESSION PARAM
var param = Expression.Parameter(typeof(PERSON));
Func<PERSON, Object> sortExpression = Expression.Lambda<Func<AuditLogs, Object>>(Expression.Convert(Expression.Property(param, sortColumn), typeof(Object)), param).Compile();
if (sort == "DESC")
result = result.OrderByDescending(sortExpression).ToList();
else
result = result.OrderBy(sortExpression).ToList();
OTHERS METHOD
public Func<T, Object> GetExpression<T>(String sortby)
{
var param = Expression.Parameter(typeof(T));
var sortExpression = Expression.Lambda<Func<T, Object>>(Expression.Convert(Expression.Property(param, sortby), typeof(Object)), param);
return sortExpression.Compile();
}
Func<PERSON, Object> sortExpression = Expression.Lambda<Func<AuditLogs, Object>>(Expression.Convert(Expression.Property(param, sortColumn), typeof(Object)), param).Compile();
if (sort == "DESC")
result = result.OrderByDescending(sortExpression).ToList();
else
result = result.OrderBy(sortExpression).ToList();
OTHERS METHOD
public Func<T, Object> GetExpression<T>(String sortby)
{
var param = Expression.Parameter(typeof(T));
var sortExpression = Expression.Lambda<Func<T, Object>>(Expression.Convert(Expression.Property(param, sortby), typeof(Object)), param);
return sortExpression.Compile();
}
result = result.OrderBy(GetExpression<PERSON>(sortColumn)).ToList();
Friday, May 23, 2014
LINQ Distinct with a property
Comparer(No work)
Group By Method(work)
result = result.GroupBy(cust => cust.Name).Select(grp => grp.First()).ToList();
Group By Method(work)
result = result.GroupBy(cust => cust.Name).Select(grp => grp.First()).ToList();
Monday, May 19, 2014
C# - Render HTML tags in GridView
HTML Code <b> will not show in the Grid, so need to HTML Decode.
BoundField
<asp:BoundField DataField="MyColumn" HtmlEncode="True" />
ItemTemplate
<ItemTemplate>
<asp:Label runat="server" Text='<%#System.Web.HttpUtility.HtmlEncode(Convert.ToString(Eval("Name"))) %>' />
</ItemTemplate>
Thursday, May 8, 2014
Debug WCF Service in IIS
- Set the breakpoints in the WCF service.
- Change the build path of the WCF service application to the bin directory of the service hosted in the IIS.( (Properties Host > Build OutputPath > IIS Bin Folder)
- Build the WCF application in the debug mode.
- Run the project application.
- Attach the 'W3WP' process to it. If in case you are not getting the process select "All Process" checkbox.
ASP.NET Session State Vs ViewState
Session State
View State
Conclusion
If data you store in the view state is not large enough to cause slow performance , use view state.
If you store too much data in session and you create many sessions in a short period with many of your concurrent users, you would be killing your server.
- Across Multiple Page.
- Saved in a specific session, cleared when the session dies (usually after 20 minutes of inactivity).
- Saved in Server.
- valid for any type of objects.
public List<Contact> SessionContacts
{
get { return (List<Contact>)HttpContext.Current.Session["SessionConacts"]; }
set { HttpContext.Current.Session["SessionConacts"] = value; }
}
View State
- Only that web page.
- It is stored in a hidden field.
- Saved in page, travels up and down between client and server.
- No expiration date.
- Valid for Serializable data only.
public List<Contact> SessionContacts
{
get { return (List<Contact>)ViewState["VSConacts"]; }
set { ViewState["VSConacts"] = value; }
}
Conclusion
If data you store in the view state is not large enough to cause slow performance , use view state.
If you store too much data in session and you create many sessions in a short period with many of your concurrent users, you would be killing your server.
Subscribe to:
Posts (Atom)