Created
May 11, 2011 20:44
-
-
Save jonezy/967304 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI.WebControls; | |
using MiniRideAndDrive.Web.Data; | |
public static partial class Helpers { | |
public static string BaseUrl { | |
get { return HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/"); } | |
} | |
public static void SetSelectedListItem(this DropDownList ddl, string value) { | |
ListItem li; | |
li = ddl.Items.FindByValue(value); | |
if (li != null) li.Selected = true; | |
} | |
public static void PopulateItems(this DropDownList ddl, object dataSource, string dataTextField, string dataValueField, string firstItemText) { | |
if (ddl == null) | |
return; | |
ddl.DataTextField = dataTextField; | |
ddl.DataValueField = dataValueField; | |
ddl.DataSource = dataSource; | |
ddl.DataBind(); | |
if(!string.IsNullOrEmpty(firstItemText)) | |
ddl.Items.Insert(0, new ListItem(firstItemText, "null")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment