Single radio button selection in Listview | Gridview | Repeater using javascript

function SelectSingleRadiobutton(rdbtnid) {
var rdBtn = document.getElementById(rdbtnid);
var rdBtnList = document.getElementsByTagName(“input”);
for (i = 0; i < rdBtnList.length; i++) {
if (rdBtnList[i].type == "radio" && rdBtnList[i].id != rdBtn.id) {
rdBtnList[i].checked = false;
}
}
}

By Prithu Banerjee Posted in ASP.NET

Set active menu item based on the current URL


jQuery(document).ready(function(){

//Call Set Navigattion function here
SetNavigation();

function SetNavigation()
{
var _prithuPath = window.location.pathname;
_prithuPath = _prithuPath.replace(/\/s/, "");
_prithuPath = decodeURIComponent(_prithuPath);

jQuery('nav ul li a').each(function () {
var href = jQuery(this).attr('href');
if (_prithuPath.substring(0, href.length) == href) {
jQuery('nav ul li').removeClass('active');
jQuery(this).closest('li').addClass('active');
}
});

});

}

By Prithu Banerjee Posted in JQuery

Important REGULAR EXPRESSIONS Validation

1. Name with space allowed
Regular Expression : ^[a-zA-Z”-‘\s]{1,40}$
Detail : The expression allows user to enter name (alphabets only) with space allowed.
String Passes : ‘denial’, ‘denial Wayne’
String Fails : ‘denial-wayne’,’denial45wayne’

2. Mobile Number (Indian)
Regular Expression : ^[789]\d{9}$
Detail : The expression allows only mobile number starting with digits 7, 8 & 9.
String Passes : ‘7856128945’, ‘9998564723’
String Fails : ‘0924645236’,’6589451235′

3. Landline Number (Indian)
Regular Expression : ^[0-9]\d{2,4}-\d{6,8}$
Detail : This is indian phone number. where it will take a format of std code 3 to 4 digits, hypen and rest of the 6 to 8 digits.
String Passes : ‘0222-895612’, ‘098-8956124’
String Fails : ‘04512-895612′,’0226-895623124′

4. Date
Regular Expression : (0[1-9]|[12][0-9]|3[01])[-](0[1-9]|1[012])[-]((175[7-9])|(17[6-9][0-9])|(1[8-9][0-9][0-9])|([2-9][0-9][0-9][0-9]))
Detail : This expression supports dates from 1-1-1757 to 31-12-9999.
String Passes : ’02-12-1889′, ’23-01-2012′
String Fails : ’23-15-8912′,’32-56-1523’

5. Username
Regular Expression : ^[a-z0-9_]{3,16}$
Detail : Allows username with length at least 3 to max 16 and there should be only lowercase letters, numbers or underscore in the username.
String Passes : ‘denial_12’, ‘asi_12devid’
String Fails : ‘Dean12′,’devid@45’

6. Non-Negative Number
Regular Expression : [+]?[0-9]*\\.?[0-9]*
Detail : The expression allows only non-negative numbers.
String Passes : ‘1245’, ‘12.56’
String Fails : ‘-45′,’-1.203′

7. Password [Type-1]
Regular Expression : ^(?![0-9]{6})[0-9a-zA-Z]{6}$
Detail : Password must 6 in length consists numbers and letters. And there must be at least one letter in it.
String Passes : ’45Deni’, ‘4589h1’
String Fails : ‘124561’,’denial45′

8. Password [Type-2]
Regular Expression : ^[a-zA-Z]\w{3,14}$
Detail : Password must start with a letter and it must contain at least 4 characters but not more than 16. No characters other than letters, numbers and underscore may be used.
String Passes : ‘deni_45’, ‘d_895623’
String Fails : ‘den’,’denial45wayne_562′

9. Password [Type-3]
Regular Expression : ^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$
Detail : Password must be at least 4 characters, no more than 8 characters, and must include at least one upper case letter, one lower case letter, and one numeric digit.
String Passes : ‘Deni12’, ‘den12D’
String Fails : ‘784512’,’denial45′

10. Password [Type-4]
Regular Expression : (?=^.{8,}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$
Detail : Passwords will contain at least (1) upper case letter, at least (1) lower case letter and at least (1) number or special character. Passwords must be at least 8 characters in length.
String Passes : ‘deni7Don’, ‘@dil45Ds’
String Fails : ‘dE7@al’,’denial45′

Validate TextBox For Digits, Alphabets, AlphaNumeric Characters

AlphaNumeric

 

 

Digits

 

 

Alphabets

 

 

 Method 2

In Method 2, Regular Expression is used for validation. Namespace that will be used is

 

Alphabets

 

 

Digits

 

 

AlphaNumeric

 

By Prithu Banerjee Posted in ASP.NET

Display Image Preview without saving file physically after upload in ASP.Net

 

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["Image"] = null;
}
}
protected void Upload(object sender, EventArgs e)
{
Session["Image"] = FileUpload1.PostedFile;
Stream fs = FileUpload1.PostedFile.InputStream;
BinaryReader br = new BinaryReader(fs);
byte[] bytes = br.ReadBytes((Int32)fs.Length);
string base64String = Convert.ToBase64String(bytes, 0, bytes.Length);
Image1.ImageUrl = "data:image/png;base64," + base64String;
Panel1.Visible = true;
}
protected void Save(object sender, EventArgs e)
{
HttpPostedFile postedFile = (HttpPostedFile)Session["Image"];
postedFile.SaveAs(Server.MapPath("~/Uploads/") + Path.GetFileName(postedFile.FileName));
Response.Redirect(Request.Url.AbsoluteUri);
}
protected void Cancel(object sender, EventArgs e)
{
Response.Redirect(Request.Url.AbsoluteUri);
}
>

By Prithu Banerjee Posted in ASP.NET

Listview dropdownlist databinding in editmode

protected void List_ItemDataBound(object sender, ListViewItemEventArgs e)
{

  //Verify there is an item being edited.
  if (List.EditIndex >= 0)
  {

    //Get the item object.
    ListViewDataItem dataItem = (ListViewDataItem)e.Item;

    // Check for an item in edit mode.
    if (dataItem.DisplayIndex == List.EditIndex)
    {

      // Preselect the DropDownList control with the Title value
      // for the current item.

      // Retrieve the underlying data item. In this example
      // the underlying data item is a DataRowView object.        
      DataRowView rowView = (DataRowView)dataItem.DataItem;

      // Retrieve the Title value for the current item. 
      String title = rowView["Title"].ToString();

      // Retrieve the DropDownList control from the current row. 
      DropDownList list = (DropDownList)dataItem.FindControl("lstEditCountry");

      //********populate the ddl here***********

      // Find the ListItem object in the DropDownList control with the 
      // title value and select the item.
      ListItem item = list.Items.FindByText(title);
      list.SelectedIndex = list.Items.IndexOf(item);

    }
  }
}
By Prithu Banerjee Posted in ASP.NET

How to get checkbox is checked

jQuery(document).ready(function () {
        jQuery('.chk input').click(function () {
            var chk = $(this).is(':checked');
            if (chk) {
                jQuery(this).closest('tr').addClass('highlight');
            }
            else {
                jQuery(this).closest('tr').removeClass('highlight');
            }
        });
    });
By Prithu Banerjee Posted in JQuery

Display Message Box in Asp.net using jQuery UI

public static void MyMessageBox(Page page, string Message, string Title)
{
StringBuilder sb = new StringBuilder();
sb.Append(“jQuery(document).ready(function(){“);
sb.Append(“jQuery(‘<div title=” + Title + “><b>” + Message + “</b></div>’).appendTo(‘body’);”);
//sb.Append(“jQuery(‘<div style=display:block; width:300px; margin:auto title='”+Title+”‘><div style=padding:10px><b>” + Message + “</b></div></div>’).appendTo(body);”);

sb.Append(“jQuery(‘.pop’).dialog({“);
sb.Append(“modal: true,”);
sb.Append(“closeOnEscape: true,”);
sb.Append(“width: 300,buttons: { Ok: function() {jQuery( this ).dialog(‘close’);} }”);
sb.Append(“});”);
sb.Append(“});”);
page.ClientScript.RegisterStartupScript(typeof(Page), “Prithu”, sb.ToString(), true);
}

Convert rows into columns in SQL Server 2008

DECLARE @cols AS NVARCHAR(MAX),
@query AS NVARCHAR(MAX)

select @cols = STUFF((SELECT distinct ‘,’ + QUOTENAME(FinancialYear)
from vw_FinancialPosition
FOR XML PATH(”), TYPE
).value(‘.’, ‘NVARCHAR(MAX)’)
,1,1,”)
print @cols
set @query = ‘SELECT Particulars,’ + @cols + ‘
from
(
select Particulars,Amount,FinancialYear
from vw_FinancialPosition
) x
pivot
(
max(Amount)
for FinancialYear in (‘ + @cols + ‘)
) p ‘

execute(@query)