This article contains GridView template column formatting through Data Format String, ternary operator blocks and custom methods.
Using Format String
Date time
<itemtemplate>
<asp:Label ID="lblDOB" runat="server" Text='<%# Eval("DOB","{0:d}") %>'></asp:Label>
</itemtemplate>
</asp:TemplateField>
For Long Date,
<itemtemplate>
<asp:Label ID="Label8" runat="server" Text='<%# Eval("DOB","{0:d}") %>'></asp:Label>
</itemtemplate>
</asp:TemplateField>
Using ternary operator
<ItemTemplate>
<asp:Image
ID="ImageOpenPending" runat="server"
ImageUrl='<%# Convert.ToInt32(Eval("StateId")) == 1 ? "~/images/icons/DashBoard_Green_Bullet.gif" : "~/images/icons/DashBoard_Red_Bullet.gif" %>' />
<asp:HyperLink ID="HyperLinkWorkOrderSummery" runat="server"
NavigateUrl='<%# "~/AuthUser/WorkOrder_Main.aspx?Id=" + HttpUtility.UrlEncode(DataBinder.Eval(Container.DataItem,"Id").ToString()) + "&mode=View" %>' > <%#Convert.ToDateTime(Eval("StartDate")).ToShortDateString().ToString() + " ," %>
</asp:HyperLink>
</ItemTemplate>
Using a code behind custom method
<ItemTemplate>
<asp:Label ID="LabelPublicComment" runat="server" ToolTip='<%# Eval("PublicComment") %>'
Text='<%# FormatName(DataBinder.Eval(Container.DataItem, "PublicComment")).ToString() %>'>
</asp:Label>
</ItemTemplate>
Write this method in code behind
protected string FormatName(object description)
{
string desc = Convert.ToString(description);
if (desc.Length > 25)
return desc.Substring(0, 25) + "..";
else
return desc;
}
Monday, July 13, 2009
Wednesday, January 07, 2009
MD5 Crisis
Now MD5 hash function is said to be no longer reliable and recommended to go for SHA1 SHA2
More…
http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html
news.google.com
More…
http://userpages.umbc.edu/~mabzug1/cs/md5/md5.html
news.google.com
Thursday, December 18, 2008
KGB Archiver - What a compression
Recently one of my friends introduced me a new archiving software that having an unbelievable compression ratio with its maximum mode,
Plus unbelievable duration for compression, don’t worry anyway they have provided “turn off the machine after compression” facility ;)
KGB Archiver - http://kgbarchiver.net/?page=home
Plus unbelievable duration for compression, don’t worry anyway they have provided “turn off the machine after compression” facility ;)
KGB Archiver - http://kgbarchiver.net/?page=home
Friday, July 04, 2008
Customer who developed a Open Source Charting Component
We have found a interesting open source Flash Charting component which
is free at the moment :)
What made him write the component...?
http://teethgrinder.co.uk/open-flash-chart/
is free at the moment :)
What made him write the component...?
http://teethgrinder.co.uk/open-flash-chart/
Thursday, May 15, 2008
How to find the control that caused the Page Submit in FormLoad event - ASP.NET
This function would be useful when someone needs to identify button clicks outside the respective button event
Changing the selected object type, it's possible to find other controls as well.
public static System.Web.UI.Control GetPostbackControlObject(System.Web.UI.Page pageReference)
{
System.Web.UI.Control returnObj = null;
if (pageReference.IsPostBack)
{
//- Find postback control's Name in form __EVENTTARGET field...
object eventTarget = pageReference.Request.Form["__EVENTTARGET"];
//- if __EVENTTARGET has a value (not null or an empty string), return the control with that name
if ((eventTarget != null) && eventTarget.ToString().Trim().Count()>0)
{
return pageReference.FindControl(eventTarget.ToString().Trim());
}
//- That is not working if the postback is trigered by a standard Buttons.
// Get the control from the Page.Form collection.
foreach (string keyName in pageReference.Request.Form)
{
System.Web.UI.Control selectedControl = pageReference.FindControl(keyName);
// Found & a Button
if ((selectedControl != null) && (selectedControl is Button))
{
returnObj = selectedControl;
break;
}
}
}
return returnObj;
}
Changing the selected object type, it's possible to find other controls as well.
public static System.Web.UI.Control GetPostbackControlObject(System.Web.UI.Page pageReference)
{
System.Web.UI.Control returnObj = null;
if (pageReference.IsPostBack)
{
//- Find postback control's Name in form __EVENTTARGET field...
object eventTarget = pageReference.Request.Form["__EVENTTARGET"];
//- if __EVENTTARGET has a value (not null or an empty string), return the control with that name
if ((eventTarget != null) && eventTarget.ToString().Trim().Count()>0)
{
return pageReference.FindControl(eventTarget.ToString().Trim());
}
//- That is not working if the postback is trigered by a standard Buttons.
// Get the control from the Page.Form collection.
foreach (string keyName in pageReference.Request.Form)
{
System.Web.UI.Control selectedControl = pageReference.FindControl(keyName);
// Found & a Button
if ((selectedControl != null) && (selectedControl is Button))
{
returnObj = selectedControl;
break;
}
}
}
return returnObj;
}
Thursday, April 17, 2008
Format HTML - Visual Studio 2005
it's very easy t format HTML or the mark up in a page using VS 2005
1. Select a part or the page which contains html
2. Select "Edit" menu and then select "Advanced" there are many useful options available
note: it's always better to check things in your menus when you tired with your coding
3. Select format document or format selection accordingly, VS will do the formatting for you
Wednesday, January 09, 2008
Debug Stored Procedures (SPs) in Visual Studio .NET
Though I have heard of it I never wanted to try it till yesterday, the debugging a SP in Visual Studio .NET is a straight forward job as follows
- Open your project
- Add a New Connection to Visual Studio
- Open your project
- Add a New Connection to Visual Studio
Select and open the respective SP and break point can be added
then right click on the Stored Procedure in the Server Explorer, select Step into Stored Procedure
"One more setting"
– go to the project settings, Set Debuggers SQL Server true
"Happy Debugging"
Subscribe to:
Posts (Atom)