Change BackGround Color of a Row in Gridview when user moves mouse on a particular selecting Row, without postback.
You need write the code in RowDataBound Event of Gridview,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
In this RowDataBound event add onmouseover and onmouseout Events.
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='blue'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='white'");
}
when the user Moves Mouseover or MouseOut on Gridview the Particular selecting Row on gridview changes the BackGround Color without postback.
Regular Expression Validater for Number Format : Format Like 11,111,22,33333,1,2222
^([1-9]{1}[0-9]{0,})+((,[1-9]{1}[0-9]{0,}){0,1})+[ ]{0,}$
Match :
11,22,3333,44,555 + Space at Last Position.
Non Match :
11,ee22,3333
11,22,33333
11, 22 ,333
1 1,22,3333
Ajax:
Ajax (also known as AJAX), shorthand for "Asynchronous JavaScript and XML", is a development technique used for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user requests a change. This is intended to increase the web page's interactivity, speed, functionality, and usability.
Figure 1: The traditional model for web applications (left) compared to the Ajax model (right).
An Ajax application eliminates the start-stop-start-stop nature of interaction on the Web by introducing an intermediary — an Ajax engine — between the user and the server. It seems like adding a layer to the application would make it less responsive, but the opposite is true.
Instead of loading a web page, at the start of the session, the browser loads an Ajax engine — written in JavaScript and usually tucked away in a hidden frame. This engine is responsible for both rendering the interface the user sees and communicating with the server on the user’s behalf. The Ajax engine allows the user’s interaction with the application to happen asynchronously — independent of communication with the server. So the user is never staring at a blank browser window and an hourglass icon, waiting around for the server to do something.
Implementation AJAX in ASP.Net
Step 1).
Down Load Ajax dll from above link add to References to Web Application
Step 2).
Set Web.Configure file Http Handlers Section
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax"/>
</ httpHandlers>
Step 3).
Where you need to bring data from Database with out Refreshing Page, for those events you need to
write code in Ajax Methods
Ex:
[Ajax.AjaxMethod]
public int calback()
{
//Write code to connect Database and return data
}Step 4).
To call Ajax Method by JavaScript, the methods which are lies in a Dot net Class
you need to add that class to AJAX, Utility in the Page load Event of ASPX Page
Ajax.Utility.RegisterTypeForAjax(typeof(Employee)); //Employee is Class Name
Step 5).
After Adding Dot net Class to Ajax, Utility. you can call those ajax methods which are lies in
that Class by the JavaScript function
function calajaxmethod()
{
Employee.calback(Callbackscriptfunction); //Calling Ajax Methods which lies in Employee Class
}
function Callbackscriptfunction(returnvalue) //After Return the Values from Ajax method
{ //storing return value in a text box
document.form1.text1.value = returnvalue.value;
}
step 6).
When Ever you call the JavaScript calajaxmethod() in an any Event it can call the Ajax method in
Dot net Class file, where you made the Database Connectivity to Bring value from Data base.
Creation of .Zip file in C#
Required Name Space using ICSharpCode.SharpZipLib.Zip;
Here by I am providing code to Create a Zip file
Ex:
public void SelectedFilesToZip()
{
using (ZipOutputStream s = new ZipOutputStream(File.Create("File Path & Name to Create")))
{
s.SetLevel(9); // 0 - store only to 9 - means best compression
byte[] buffer = new byte[4096];
foreach (string file in Arlist_FilePath)
{
System.IO.FileInfo filepath = new System.IO.FileInfo(file);
if (filepath.Exists)
{
string extension = System.IO.Path.GetExtension(file);
if (extension.ToString().Trim().ToUpper() != ".ZIP")
{
// Using GetFileName makes the result compatible with XP
// as the resulting path is not absolute.
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
// Setup the entry data as required.
// Crc and size are handled by the library for seakable streams
// so no need to do them here.
// Could also use the last write time or similar for the file.
entry.DateTime = DateTime.Now;
s.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
// Using a fixed size buffer here makes no noticeable difference for output
// but keeps a lid on memory usage.
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
s.Write(buffer, 0, sourceBytes);
} while (sourceBytes > 0);
}
}
}
}
s.Finish();
// Close is important to wrap things up and unlock the file.
s.Close();
}
}
Validation Expression For Date & Time
Expression become true
04-05-2007 10:00:00 PM
04-05-2007 10:00:00
04-05-2007 14:00:00
04-05-2007 10:00 PM
04-05-2007
Expression become false
04-05-2007 14:00:00 AM
Validation Expression =
^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))
(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|
[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]
|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$"
Send Mail with Images as Thumbnails
If the Image existed in you Server,
Dim mailMessage As System.Net.Mail.MailMessage = New System.Net.Mail.MailMessage()
'Baic Mail Infomation
mailMessage.From = New System.Net.Mail.MailAddress("from@gmail.com")
mailMessage.To.Add("to@gmail.com")
mailMessage.Subject = "Mail Subject"
'Create two views, one text, one HTML.
Dim plainTextView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("body Infomation", Nothing, "text/plain")
Dim htmlView As System.Net.Mail.AlternateView = System.Net.Mail.AlternateView.CreateAlternateViewFromString("body Infomation" + "image Path", Nothing, "text/html")
'Add two views to message.
mailMessage.AlternateViews.Add(plainTextView)
mailMessage.AlternateViews.Add(htmlView)
'Send message
Dim smtpClient As New System.Net.Mail.SmtpClient()
smtpClient.Send(mailMessage)
****Note - image path : < img src='http://www.mydomain.com/images/my_image.gif' / >