Skip to main content

Posts

Showing posts from July, 2009

Enum To ListItem Collection

private System.ComponentModel. BindingList < ListItem > EnumToList( Type enumType) { System.ComponentModel. BindingList < ListItem > listItemBindingList = new System.ComponentModel. BindingList < ListItem >(); foreach ( Enum item in Enum .GetValues(enumType)) { ListItem lItem = new ListItem(item.ToString("D"), item.ToString("G")); listItemBindingList.Add(lItem); } } you can call the method BindingList<ListItem> listItemBindingList = EnumToList(typeof(YourEnum));

ASP.NET GridView - Format Template column data using format strings and Custom Methods

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:H