Posts

Showing posts from 2012

Programmatically Zip and UnZip the files in .NET

Normally we may find the functionality to Zip and Unzip the file pro grammatically.We have many third party components to do this operation.Here I am going to present Zip and Unzip files using "CGZipLibrary.dll" in C#.NET.

To do this we need to download the CGLibrary.dll from this link and register this dll.

The zip file contains 3 DLL's:
CGZipLibrary.dllzip32.dllUnzip32.dll Open the command prompt in administrator mode.Now we need to register this CGZipLibrary.dll as given below

regsvr32 filepath\filename

Ex: regsvr32 D:\Download\CGLibrary.dll

After registering the dll and Copy zip32.dll and unzip32.dll to

c:\windows\system32 directory or c:\winnt\system32.

Unzip the file you need to do like this

 string SrcPath = @"D:\StudentReports.zip";
            string DestPath = @"D:\ZippedFiles";             try             {                 CGUnzipFiles oUnzip = new CGUnzipFiles();                 oUnzip.ZipFileName = SrcPath;                 oUnzip.ExtractDir = …

Bind the Events to the Dynamically Created Rows in a HTML Table

I found a solution to bind the events to the dynamically created buttons in a HTML.Some times we need to add a row to the existing HTML table with some inputs.That dynamically created row is not visible in the page source.Try It !

So to attach the events also we need to do like this


var newRow ="<tr> <td></td> <td><input type='text' id='tbNameDyn'/></td> <td> <input type='text' id='tbAgeDyn'/></td> <td><input type='checkbox' id='tbResultDyn'/></td><td><input type='submit' name='submitButton' value='Save Row' id='btnSaveRowDyn' onclick='DynButtonClick();'> </td></tr>";// $('#webgrid > tbody:last'). $('#webgrid tbody:last').append(newRow);Here I have binded the button with the event "onClick" function "DynButtonClick".See the Code too


function D…

Make the Textbox as Label using CSS

This is a simple tip to make the textbox as label in the Web Pages.We need to just add a simple CSS to the input text.See code snippet


.textboxAslabel {border:none;background-color:#FFF;border-color:#FFF;}
Here I have mentioned the background-color and border-color as "white".In my application the background-color is white.So according to your background-color change it.Now Apply that to the textbox.See this Image


Single to handle multiple "Submit" button Clicks in MVC3 Razor View

Last week, I have faced a problem on handling the multiple "Submit"  buttons clicks in a View.I am not very good at MVC3 but I want to share my experience so that others can find some solution regarding this problem.

Suppose we have many Submit buttons in a View where we want to handle the different functions. In the Controller of the We need to write the Code for different submit buttons as given below

[AcceptVerbs(HttpVerbs.Post)]public ActionResult FormActions(string submitButton){switch(submitButton.ToLower()){case"click to know date":this.SetNotification(DateTime.Now.Date.ToString("dd-MMM-yyyy"), NotificationEnumeration.Success,true);return View("index");break;case"click to know time":this.SetNotification(DateTime.Now.ToString ("T"), NotificationEnumeration.Success,true);return View("index");break;default:return View("index");break;}}The View Code is given bel…

Difference between the SCOPE_IDENTITY(),@@IDENTITY and IDENT_CURRENT in Sql Server

SCOPE_IDENTITY(),@@IDENTITY and IDENT_CURRENT('table_name') are the SQL SERVER Functions which will return the last inserted record Identity Value.

Normally in the development stage we need to get the last inserted row information using SQL Query.

Lets go in deep to understand the differences between these three functions.

@@IDENTITY :

@@IDENTITY will return the Identity value generated in a table irrespective of the scope.The main advantage lies here when we have a trigger on a table that causes anidentity to be created in another table,you will get the identity that was created last since it gets the identity regardless of the table.

Syntax :SELECT @@IDENTITY;

SCOPE_IDENTITY():

SCOPE_IDENTITY() also returns the Identity Value generated in a table with in the same scope regardless of the table that produced the value.

Syntax:SELECT SCOPE_IDENTITY();

IDENT_CURRENT('table_name'):

It will returns the last Identity value produced in a table regardless of the connection that create…

Set the Default Value to the Column Of a Table Programmaticaly

Normally we face this type of problem when we want to set the column default value pro-grammatically.

To Solve this problem we need to first get the table column information using this Query.

"SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='person'".

Here the table name may vary.

when we execute this Query we will get the each column information .So based on this we can Iterate the each column and get the each column Information as given below 


VB.NET 
Private Sub Initialise_The_Table(ByVal ReqTab As String) On Error GoTo handle_error Dim eachTableAdapter As SqlDataAdapter Dim tableDataset As New DataSet Dim adoHelper As SQLHelper = SQLHelper.GetInstance eachTableAdapter = adoHelper.GetAdapter("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + ReqTab + "'") eachTableAdapter.FillSchema(tableDataset, SchemaType.Source, ReqTab) eachTableAdapter.Fill(tableDataset, Req…

Context Menu in ASP.NET

Image
We normally face a task like to show Menu when we right click the gridview or treeview e.t.c.

Many third party controls are providing this right click context Menu to the controls like one of the best third party control like Telerik.

But we can do this type of requirements using jQuery also.

To do this in ASP.NET we need to download the jQuery Context Menu plugin.

We need frame the menu div based on our requirement.See this example to do <div>
<ulid="myMenu"class="contextMenu">
<liclass="edit"><ahref="#edit">Edit Node</a></li>
<liclass="delete"><ahref="#delete">Delete Node</a></li>
</ul>
</div>

* This source code was highlighted with Source Code Highlighter.After downloading the plugin you need to add this lines in your .aspx page

<script src="jquery.contextMenu-1.01/jquery.contextMenu.js" type="text/javascript"></script>
  <link …

Decide Cursor Type and Lock Type based on CRUD Operation

Normally when we do the addition and deletion of record in the ADODB,cursor type and lock type will be changed.So we need to be very careful while adding and deleting a record using the record set object.So for this I have done a sample on addition only.
1. When we want to add using the record set object we need to pass the Cursor Type and Lock Type as
    ADODB.CursorTypeEnum.adOpenDynamic
   ADODB.LockTypeEnum.adLockOptimistic

2. By default, ADO record sets are opened with a lock type of adLockReadOnly, which does not allow additions and deletions.
3. To allow additions and deletions, open the record set with a lock type of either adLockOptimistic or adLockPessimistic
To Solve this we need change the code like this

Dim recordSetObj AsNew ADODB.RecordSet recordSetObj .Open("select * from students","Your Connection Object", ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockOptimistic)IfNot recordSetObj .EOFThen recordSetObj .AddNew()EndIf'…

Get the Clicked Cell Value and Column Name of GridView in ASP.NET

Image
Normally we find the requirement to get the selected Cell Clicked Value .In rare cases we need to find the Column Name and Index of the Cell clicked in the GridView.

This is some how tricky work to get the Column name and index also.We can do this in many ways .

We must be very much thankful to the jQuery contributors for such beautiful lightweight,fast and concise Library.

Really this is very good  we can't iterate the table loop to the clicked cell value.
With a Single we can get the clicked Value.Look at this line of Code
$('#gv>tbody>tr>td').text();

For this requirement I have taken a grid which i have given a static datasource.
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { AddData(); } } public void AddData() { try { DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(Int32)); dt.Columns.Add("Name…

Convert DataSet or DataTable to XML

Normally we face this problem where we have lots of data to convert into XML file from DataSet or DatTable  .Because XML file is readable by all languages.

Here I have some sample Snippet for Writing the DataSet or DataTable to XML format.

DataSet ds = new DataSet(); using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["CON"].ConnectionString)) { con.Open(); string Query = "select col1,col2 from table "; SqlDataAdapter da = new SqlDataAdapter(Query, con); da.Fill(ds,"TableName"); ds.Tables["TableName"].WriteXml("XML File Path"); }

Hope this help you :-)

Any Suggestion s on this article are welcome :-)

jQuery to Validate password and confirm password

Image
This article is mainly focused on the validating the password and Confirm password using Client Side Scripting "jQuery".

Normally we have password and confirm password in the regsitration page where we need to validate the password and confirm password.

This can also be done using the compare validator also in Asp.Net.

In this demo I have taken two textboxes where i set the textmode as "password".Now in the button click I am validating the both fields has same value or not.

HTML Markup:



Code :



Here I have written like if both the values are same then excute the server code as "return 1==1"  :-) which means execute the server code.


Any suggestion on this article are welcome .
Hope this may help :-)




Swapping of ListBox Items using jQuery

Image
The interchanging of Items of one list-box to other list-box is done in this Swapping of List-box Items.Here the swapping is done in the Client Side using jQuery.For Swapping the Items  I took  two Array lists .

Initially I have filled the two array lists with the list boxes data.Now I have written a Common Method to swap the Items from one list box to other.

HTML Markup:


<div> <asp:ListBox runat="server" ID="lstbx1"> <asp:ListItem Text="text1" /> <asp:ListItem Text="text2" /> <asp:ListItem Text="text3" /> <asp:ListItem Text="text4" /> </asp:ListBox> <br /> <asp:ListBox runat="server" ID="lstbx2"> <asp:ListItem Text="text5" /> <asp:ListItem Text="text6" /> <asp:ListItem Text="text7" /> …

Restrict the Textbox to enter only Numbers Using Javascript

Normally we get this type of requirement to accept only numbers in a text box.Suppose we have a Credit Card Number entry where we want to validate the key-press is number or not.Here i have simplified the way to enter only numbers in the text-box.Here i have written some logic to enter only numbers in textbox using javascript.
<script type="text/javascript">function isNumberKey(evt){var charCode =(evt.which)? evt.which : event.keyCode if(charCode >31&&(charCode <48|| charCode >57))returnfalse;returntrue;}<script>
Now we can call this function in theevents like keypress,keydown and keyup to validate the value is number or not.

Happy Coding :-)