My blog moved to http://dev.kratik.net
Please visited my new blog at http://dev.kratik.net
ASP.NET – Working with Gridview TemplateFields
1. code behide
public string ComputeSeniorityLevel(TimeSpan ts)
{
int numberOfDaysOnTheJob = ts.Days;
if (numberOfDaysOnTheJob >= 0 && numberOfDaysOnTheJob <= 1000) return “Newbie”; else if (numberOfDaysOnTheJob > 1000 && numberOfDaysOnTheJob <= 4000) return “Associate”; else if (numberOfDaysOnTheJob >= 4000 && numberOfDaysOnTheJob <= 8000)
return “One of the Regulars”;
else
return “An Ol’ Fogey”;
}
2. html
<asp:GridView ID="GridView1" Runat="server"
DataSourceID="employeeDataSource" AutoGenerateColumns="False"
BorderWidth="1px" BackColor="White" GridLines="Vertical"
CellPadding="4" BorderStyle="None"
BorderColor="#DEDFDE" ForeColor="Black">
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<PagerStyle ForeColor="Black" HorizontalAlign="Right"
BackColor="#F7F7DE"></PagerStyle>
<HeaderStyle ForeColor="White" Font-Bold="True"
BackColor="#6B696B"></HeaderStyle>
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
<Columns>
<asp:BoundField HeaderText="Last" DataField="LastName"
SortExpression="LastName"></asp:BoundField>
<asp:BoundField HeaderText="First" DataField="FirstName"
SortExpression="FirstName"></asp:BoundField>
<asp:BoundField HeaderText="Hire Date" DataField="HireDate"
SortExpression="HireDate"
DataFormatString="{0:d}"></asp:BoundField>
<asp:TemplateField HeaderText="Seniority">
<ItemTemplate>
<%# ComputeSeniorityLevel(DateTime.Now –
(DateTime)Eval("HireDate")) %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True"
BackColor="#CE5D5A"></SelectedRowStyle>
<RowStyle BackColor="#F7F7DE"></RowStyle>
</asp:GridView>
ref: http://msdn.microsoft.com/en-us/library/aa479353(lightweight).aspx
Centering: Auto-width Margins
margin:50px 0px; padding:0px;
text-align:center;
}
#Content
{width:500px;
margin:0px auto;
text-align:left;
padding:15px;
border:1px dashed #333;
background-color:#eee;
}
How to use HtmlEncode with TemplateFields, Data Binding, and a GridView
Label ID="LabelDescription"
runat="server"
Text='<%# System.Web.HttpUtility.HtmlEncode((string)Eval("Description")) %>'
Asp.net Permalinks Using URL Rewriting
A Permalink is a permanent link which points to a particular blog entry or forum entry. For example the permalink for this blog article is http://csharp-codesamples.com/2009/03/aspnet-permalinks-using-url-rewriting.
This does not mean that a physical page is created for each blog entry. Instead a single page shows the data for multiple blogs articles dynamically based on some query string.
But all pages in asp.net end with a .aspx extension and if we pass a query string to the page it will look something like Page.aspx?query=test. These links are not very search engine friendly.
This article describes a simple method to create permalinks and improve your asp.net websites search engine optimization using URL rewriting without the use of custom handlers.
ref: http://csharp-codesamples.com/2009/03/aspnet-permalinks-using-url-rewriting/
FileUpload in UpdatePanel, ASP.NET, like Gmail
http://geekswithblogs.net/ranganh/archive/2009/10/01/fileupload-in-updatepanel-asp.net-like-gmail.aspx
asp.net + jquery
Introduction to jQuery in ASP.Net and 10 Advantages to Choose jQuery
More Fun With LINQ – Perform Common Tasks in ASP.NET
http://www.dotnetcurry.com/
http://www.dotnetcurry.com/ShowArticle.aspx?ID=320