Browsing all articles in C#.NET
Jan
27

Remove duplicates in a string array

These are the followings ways, where we can filter a string array to remove the duplicates.

HashSet   
public static string[] RemoveDuplicates(string[] s)
{
HashSet set = new HashSet(s);
string[] result = new string[set.Count];
set.CopyTo(result);
return result;
}
List 1   
private static string PreviousItem;

private static bool Match(string item)
{
    bool result = (item == PreviousItem);
    PreviousItem = item;
    return result;
}

public static string[] NoDuplicates(string[] input)
{
    PreviousItem = null;
    List<string> result = new List<string>(input);
    result.Sort();
    result.RemoveAll(Match);
    return result.ToArray();
}
Feb
23

To create directory on application server with ASP.NET server side code

Here is the code to creating the directory at application with ASP.NET

using System;
using System.Data;
using System.Configuration;
// We  need this namespace to create directory
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void  Page_Load(object sender, EventArgs e)
{
string NewDir = Server.MapPath("New  Folder");
// Call function for creating a directory
MakeDirectoryIfExists(NewDir);
}
private void  MakeDirectoryIfExists(string NewDirectory)
{
try
{
// Check if directory exists
if (!Directory.Exists(NewDirectory))
{
// Create the directory.
Directory.CreateDirectory(NewDirectory);
}
}
catch (IOException  _ex)
{
Response.Write(_ex.Message);
}
}
}
Feb
22

Gridview custom paging in asp.net 3.5 with SQL Server Sproc

GridView — Displays a set of data items in an HTML table. ASP.NET GridView control enables you to display, sort, page, select, and edit data.

Default gridview paging works best when you deal with limited pages. If there are more pages then, the performance suffers. In this case direct jump to desire page is a good alternative.

I have deal with a problem on GridView while working on user control (.ascx). I have a user control (.ascx) with GridView in it. I have used Stored Procedure to retrieve data. Bounding data to gridview display all the records and Default paging setting not work for me. Here Custom Paging helps me and only those database records that need to be displayed get retrieved. Using GridView Custom Paging solve the Issue for me.

Here, I am going to demonstrate a sample on GridView Custom Paging. I want to display records from two different tables depending on search pattern, let’s consider, I have student table contain sName, sAddress, ClassId and class table contain classId and ClassName. Now I want to display Name, Address and ClassName based on string pattern. Here I will get Ramdom Records based on search pattern. In this example we are going to use ASP.Net DropDownList along with ASP.Net GridView for Pagination to provide Jump To Page Number facility to the user.

read more

Follow us on Twitter! Follow us on Twitter!
FoxSparrow Tweets

Categories