Wednesday, October 29, 2008

Preview Default image in Gridview

Try this Code:

protected void grdtest_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image imgCarPic = (Image)e.Row.FindControl("imgCarPic");
if (string.IsNullOrEmpty(imgCarPic.ImageUrl.ToString()))
{
imgCarPic.ImageUrl = "../images/NoImageSmall.jpg";
}
else
{
String strUploadedPicPath = Server.MapPath(imgCarPic.ImageUrl.ToString());
if (!System.IO.File.Exists(strUploadedPicPath))
{
imgCarPic.ImageUrl = "../images/NoImageSmall.jpg";
}
}
}
}

Good Luck

Prevent Multiple Login at the same time

Try this:
protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
e.Cancel = Membership.GetUser(Login1.UserName).IsOnline;
}

or try this code

void Login1_LoggingIn(object sender, LoginCancelEventArgs e)
{
MembershipUser u = Membership.GetUser(Login1.UserName); Response.Write(u.IsOnline);
if (u.IsOnline)
{
Login1.FailureText = "A user with this username is already logged in."; e.Cancel = true;
}
else
{
Login1.FailureText = String.Empty;
e.Cancel = false;
}
}

ASP.NET Regular Expression for date format

In ASP.Net Many times required to Validate Date Fromat Enter in Control.in Regular Expression Following RE used to Validate Date Format.

dd/mm/yyyy Format (optional mm,optional dd)
([1-9]0[1-9][12][0-9]3[01])[- /.]([1-9]0[1-9]1[012])[- /.][0-9]{4}$

mm/dd/yyyy (optional mm,optional dd)
^([1-9]0[1-9]1[012])[- /.]([1-9]0[1-9][12][0-9]3[01])[- /.][0-9]{4}$

mm/dd/yyyy (Exact Format)
^([01]\d)/([0-3]\d)/(\d{4})$

Good Luck