Monday, January 31, 2011

Code formatter for the bloggers

The below blogspot helps you format the C#, VB code to a good-readable format for the blogger :)

http://codeformatter.blogspot.com/2009/06/about-code-formatter.html

ASP .NET Membership settings - that worked :)

Many a time, there are situations where we have to bang our head for getting asp .net membership login controls to work!
Happens,, never mind :)
Below is the snip in the web config, which worked for me and I'm sure it will work for you all too... Mainly that happens when we miss out attributes like "applicationName" etc.

Hope this helps.

 <membership defaultProvider="CustomAspNetSqlMembershipProvider">  
                <providers>  
     <clear/>  
                     <add name="CustomAspNetSqlMembershipProvider"   
        type="System.Web.Security.SqlMembershipProvider"   
        connectionStringName="eWentDatabase"   
        applicationName="/"   
        minRequiredPasswordLength="6"  
        requiresUniqueEmail="true"   
        requiresQuestionAndAnswer="true"   
        passwordFormat="Hashed" />  
                </providers>  
           </membership>  
   <roleManager enabled="true" defaultProvider="CustomRoleProvider">  
    <providers>  
     <add name="CustomRoleProvider"   
        type="System.Web.Security.SqlRoleProvider"   
        applicationName="/"   
        connectionStringName="eWentDatabase"   
        />  
    </providers>  
   </roleManager>  

Saturday, January 29, 2011

Generic method to populate dropdown list in asp .net

An attempt of making the dropdown list population easier for everyday projects :)

 ///  
 /// Populates the drop down list box with given list type.  
 ///  
 /// The dropdown list to be populated.  
 /// The data source.  
 /// The datatext field for the dropdown list.  
 /// The datavalue field for the dropdown list.  
 /// The selected value, if any.  
 /// Whether to add an empty value (e.g.--Select--).  
 public static void PopulateDropDownList(DropDownList dropDownList, IList dataSource, string dataText, string dataValue, string selectedValue, bool addEmptyValue)  
 {  
 if (dropDownList != null && dataSource != null)  
 {  
 if (dropDownList.Items != null)  
 {  
 dropDownList.Items.Clear();  
 }  
 dropDownList.DataSource = dataSource;  
 dropDownList.DataTextField = dataText;  
 dropDownList.DataValueField = dataValue;  
 dropDownList.DataBind();  
 if (addEmptyValue)  
 {  
 dropDownList.Items.Insert(0, new ListItem("--Select--", "-1"));  
 }  
 if (!string.IsNullOrEmpty(selectedValue))  
 {  
 dropDownList.SelectedValue = selectedValue;  
 }  
 }  
 }  

Wednesday, January 12, 2011