Skip to main content

Posts

Showing posts from November, 2009

Get Tables and Columns Names by LINQ

Here I am explaining one of the tricks to get all table name list along with column of it from your DataContext. I am using the System.Data.Linq.Mapping.MetaModel to get information about tables and it have much more database related information. Following are the code to list all table name along with column from your DataContext. //DataContext object. DataClassesDataContext DB = new DataClassesDataContext ();         //String variable to stor html to render. string strHtmlToLoad = "" ;         //Heading strHtmlToLoad = "<-h2->Table Names<-/h2-><-ol->" ;         //Loop through tables add name to string foreach ( var mTable in DB.Mapping.GetTables()) { strHtmlToLoad += "<-li->" + mTable.TableName + "<-ul->" ; //Loop through table's columns add name to string foreach ( var mColumn in mTable.RowType.DataMembers) strHtmlToLoad += "<-li->

Dynamic columns in Gridview

There are many types of column field are are available for grid view like BoundField ButtonField CheckBoxField CommandField HyperLinkField ImageField TemplateField Here I explain how to add dynamically Bound Field and then Template Field into grid view. First we look how to add Bound Field into Grid view and then Template Field. First of all make your AutoGenerateColumns property to false. Prepare your data source which will you going bind with grid view. it will be Data Table or Generic List of class type or structure type any thing or Table Class of your Linq dbml data contexts class. Here we are going to use Data Table as follow. DataTable dt = new DataTable ( "ItemMaster" ); dt.Columns.Add( new DataColumn ( "ItemId" , typeof ( Int32 ))); dt.Columns.Add( new DataColumn ( "ItemName" , typeof ( String ))); dt.Columns.Add( new DataColumn ( "Price" , typeof ( Decimal ))); for ( int i = 0; i < 10; i++) {    

Get website's base URL..

Following function is help you to get root path or site base URL of your web application. Like if your page URL like "http://www.blogger.com/post-create.g?blogID=5406317769839137062" this function return base URL like "http://www.blogger.com" . public static string GetApplicationPath() {      string appPath = null ;      //Getting the current context of HTTP request      HttpContext context = HttpContext .Current;      //Checking the current context content      if (context != null )      {                 //Formatting the fully qualified website url/name                 appPath = string .Format( "{0}://{1}{2}{3}" ,                 context.Request.Url.Scheme,                 context.Request.Url.Host,                 context.Request.Url.Port == 80 ? string .Empty : ":" + context.Request.Url.Port,                 context.Request.ApplicationPath);      }      return appPath; } Better One public static string GetAp

Message Panel

This in post show you how effectively you can show you messages and error regarding the user events using the Message Panel control. following are the step by step description of how to create and use Message panel. Create Message panel In your application add folder App_Code. To do that right clicking on Web project select Add Asp.net folder >> App_Code Add one class file name MessagePanel.cs and copy pest following code into it. using System; using System.Web.UI; using System.Web.UI.WebControls; namespace Controls {    // TODO: add clear link (display: none;) plus requried js    [ ToolboxData ( "<{0}:MessagePanel runat=\"server">" )]     public class MessagePanel : Panel , INamingContainer     {         private const string VSKEY_MESSAGE = "Message" ;         private const string VSKEY_ERROR = "Error" ;         bool _showMessagePanel;         bool _showErrorPanel;         string _messageCssCla