Geeks With Blogs

AzamSharp Some day I will know everything. I hope that day never comes. October 2005 Entries
Generics in C# 2.0
Generics are pretty cool. You can think of Generics as a basket which can hold different datatypes without the process of casting. Here are few examples of Generics in action: Custom Collection: You can make use of the Generics to create a custom collection. System.Collections.Generic.... users = new List<Users>(); for (int i = 0; i <= 9; i++) { Users user = new Users(); user.FirstName = "Mohammad" + i; user.LastName = "Azam" + i; users.Add(user); } // print the users from ......

Posted On Monday, October 31, 2005 10:20 AM

Hyperlink Columns in GridView Control
The code below creates a GridView control that have a hyperlink column which sends the ID to other page: Here is the simple code which you can use: <asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1" GridLines="None" AutoGenerateColumns="False"... <FooterStyle BackColor="#C6C3C6" ForeColor="Black" /> <RowStyle BackColor="#DEDFDE" ForeColor="Black" /> <PagerStyle BackColor="#C6C3C6" ......

Posted On Sunday, October 30, 2005 12:42 PM

Preventing users to go back to the previous pages
Sometimes we are in a situation that we don't want the user to visit the previous pages. This can be a scenario when the user logs out but uses the back button to navigate to the pages. In this article I will show you some simple ways you can use to prevent user from going back. Using History(+1) Method: Let's say that you have a page called DemoPage.aspx which is the secure page and when you click the button you are redirected to another page FinalPage.aspx. Now from FinalPage.aspx you don't want ......

Posted On Sunday, October 30, 2005 11:07 AM

Adding HTML Tags to the plain text at runtime
Sometimes we need to add HTML Tags to the plain text and give them a better display. A good example will be if someone sends you a plain text file containing multiple choice questions. The file will look something like this: Plain Text File: 1) What is your name and tell me where you live? a) AzamSharp *b) Mohammad Azam c) Azim d) Aziz 2) What is your pet name? a) chittab) bonco *c) cocod) billi (The '*' denotes the right answer). Now you want to parse this file and add HTML to it so that it will ......

Posted On Thursday, October 27, 2005 6:23 PM

Converting HTML to XHTML
Sometimes we are in a situation that we want to convert HTML to XHTML format. You can easily achieve this using the HTML2XHTML.dll library created by Microsoft. You can download the library at: http://www.InfoPathDev.com. Next you need to register the library. Just go to the Visual Studio.NET command prompt and go to the folder which contains the HTML2XHTMLLib.dll file and type: C:\The path to the folder which contains the dll\regsvr32.exe HTML2XHTMLLib.dll Now you can use can reference the library ......

Posted On Wednesday, October 26, 2005 11:02 PM

I am extremely busy for couple of days (NON TECH)
Hi Everyone, First of all I like to apologize for my absence and not writing any new articles for couple of days. Actually my exams, assignments and all sort of boring stuff is due these days. I will try my best to write few good articles during the weekened. Please view the articles at www.gridviewguy.com. Thanks, AzamSharp powered by IMHO ......

Posted On Wednesday, October 26, 2005 7:55 AM

Searching in the DataSet to save a Database trip
I was working on a project which used Access Database. There was one search feature where the user can search for different customers in the database. I tried to write a simple query but for some reason Access denied all my queries. Then I asked myself why not search the DataSet instead of going to the Database. (Please note this is not a good idea since for this you will have to retrieve all the rows in the DataSet from the database and also it will not provide you the flexibility which is offered ......

Posted On Tuesday, October 25, 2005 12:18 PM

Getting the HTML of the Page in a string variable
You can easily get the HTML of the page in a string variable. That html can be of a page such as yahoo.com or any other page. You only need to use the WebClient class which is in System.Net. Here is the code which retrieves the HTML of the currently running page: protected void Button1_Click(object sender, EventArgs e) { WebClient myClient = new WebClient(); string myPageHTML = null; byte[] requestHTML; // Gets the url of the page string currentPageUrl = Request.Url.ToString(); UTF8Encoding utf8 ......

Posted On Monday, October 24, 2005 9:20 PM

Dynamically accessing controls in the Master Page and Rendering Master Page on Different Browsers
Okay, I got good news Good News: If you have a Content page you can tell the that page that what master page to load on different browsers. Its pretty simple take a look at the code below: <%@ Page Language="C#" mozilla:MasterPageFile="~/M... ie:MasterPageFile="~/MyMast... AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> As you can see in the above code ie represent Internet Explorer and mozilla offcourse means Mozilla browser. powered by IMHO ......

Posted On Wednesday, October 19, 2005 10:16 PM

Is this another Visual Studio.NET 2005 BETA II BUG??
Okay, I am trying to play around with Master Pages. I read that instead of defining the MasterPageFile attribute on every page. You can simply define it in the web.config file. Unfortunately this is not working and whenever I add a new page it throws the following exception. Error 5 (0): error CS0006: Metadata file 'C:\WINDOWS\Microsoft.NET\F... ASP.NET Files\azamsharptesting\4f35... could not be found / Any Ideas? powered by IMHO ......

Posted On Wednesday, October 19, 2005 9:45 PM

Executing DTS Packages using C#
Guess what! you can execute DTS Packages from C# code. Yeah I know its pretty cool. Take a look at the code below. Don't try to run this code as you need to do lot of modifications. Check out the link I have given at the bottom of this posting. // This method will run the DTS Package private static void RunDTSPackage() { // Name of the package to run string packageName = "AzamSharpDTSTesting"; object pVarPersistStgOfHost = null; DTS.PackageClass package = new DTS.PackageClass(); package.LoadFromSQLServer("... ......

Posted On Wednesday, October 19, 2005 8:29 PM

How easy can it get ohh come on now!
Okay I am playing around with Visual Studio.NET 2005 BETA II. If you need to display data in the GridView object then you can simply open the Server Explorer and drag and drop the table which you like to be displayed on the screen. When the table is dropped on the webform it will create a GridView object automatically and displays the contents of the table. powered by IMHO ......

Posted On Tuesday, October 18, 2005 6:08 PM

Exporting DataSet to XML File
Sometime ago I wrote an article about Exporting Datagrid to Excel, Word and Text Files. Sometimes we need to export Dataset to xml file. This is pretty simple as all you need is a literal control which will render the data to the output stream. Check out the code below: SqlConnection myConnection = new SqlConnection(ConnectionStr... SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROM Categories", myConnection); DataSet ds = new DataSet(); ad.Fill(ds, "Categories"); Literal l = new Literal(); ......

Posted On Tuesday, October 18, 2005 3:52 PM

Using DataReader.RecordsAffected in ASP.NET 2.0
The DataReader object in ASP.NET 2.0 provides you with a property RecordsAffected which can be used to find the number of rows updated, deleted or inserted. You can simply use it like this: string updateQuery = "UPDATE Person SET LastName = 'Saif' WHERE PersonID IN(13,14)"; SqlConnection myConnection = new SqlConnection(ConnectionStr... SqlCommand myCommand = new SqlCommand(updateQuery, myConnection); SqlDataReader reader = null; myConnection.Open(); reader = myCommand.ExecuteReader(); while (reader.Read()) ......

Posted On Monday, October 17, 2005 5:12 PM

Sharing session between applications in In-Proc mode
First of all let me start by saying that this approach is not suitable for performance. I highly recommend you to use SQLSERVER session mode when sharing session data between applications. Anyway, I will make two applications Parent and the Child. Parent will pass the session to the Child and the Child will simply display the session variable on the screen. Database: CREATE TABLE Person (PersonID int identity(1,1) PRIMARY KEY, Username nvarchar(50), GUID nvarchar(50)) Parent Application Code: I will ......

Posted On Saturday, October 15, 2005 12:25 AM

Where do I start?
Where do I start learning .NET? This is perhaps the most asked question on www.asp.net forums. With the arrival of ASP.NET 2.0 I think it will be a better idea to start learning 2.0 instead of 1.x. The reason I am saying this is that 2.0 is quite different from 1.x. Here is some basic stuff which might help a newbie to start .NET. C++ and Java developers: If you are coming from the C++ or java background your choice should be C# since its pretty much the same syntax and you can quickly pick it up. ......

Posted On Friday, October 14, 2005 10:06 PM

Autocomplete feature in .NET 2.0 (This is so cool)
Don't you get bored typing loops like this by hand: for (int i = 0; i <= 10; i++) { } Visual Studio.NET 2005 BETA II let's you write your statement more quickly. Simple type for and press TAB two times and it will write the rest of the code for you. The following code is generated by pressing the TAB two times after writing for. After the loop is writen you can press TAB to navigate inside the loop and change the values. for (int i = 0; i < length; i++) { } Do you want to write the reverse ......

Posted On Wednesday, October 12, 2005 12:12 AM

Triplet class (Come on Now)
.NET Framework 2.0 introduces a Triplet class which is used to hold 3 items. You can also hold a single or two items but the primary purpose is to hold three items. You can use it something like this: Triplet t = new Triplet(); t.First = "Car"; t.Second = "Engine"; t.Third = "Wheels"; I think its pretty insane! powered by IMHO ......

Posted On Wednesday, October 12, 2005 12:00 AM

Accessing the value of the GridView footer row is pretty easy
No more looping through all the rows and finding which one is the footer row. ASP.NET 2.0 GridView control contains the property FooterRow which returns the footer row. Check out the following code where I get the value out of the TextBox which are in the footer row of the GridView control. string firstName = string.Empty; string lastName = String.Empty; // Gets the footer row directly Cool right! GridViewRow row = GridView1.FooterRow; firstName = ((TextBox)row.FindControl("... lastName ......

Posted On Tuesday, October 11, 2005 11:38 PM

Dynamically Writing into Web.config File
This question is asked many times on www.asp.net forums. Although its not a good idea to dynamically write anything in the web.config file reason being that writing anything in web.config will restart the application. Anyway, if for some reason you don't care about the restart and really wanted this functionality than you can look into this code: private void GetConfigSettings() { string path = Server.MapPath("Web.config"); string newConnectionString = @"Server=local;Database="+t... ......

Posted On Sunday, October 9, 2005 11:26 AM

Introducing question posting board on www.gridviewguy.com
Everyday I receive several emails from developers asking questions about my articles. To reply every single email is pretty hard so I decided why not to create a question posting forum and in this way the answer will be visible to more users. The forum is pretty simple just type the question and it will show under the particular article. You can check out the article with the question at this link (scroll down at the bottom). powered by IMHO ......

Posted On Saturday, October 8, 2005 12:46 PM

Writing text to a word file in ASP.NET
Ahhh, today is saturday woke up little early (6:00 AM). Anyway, I went to ASP.NET forums to check out some questions and one developer asked "How can I write text to a word file.". So, here is the code to write text to a word file: private void WriteToWordFile() { // Any folder string path = @"C:\ServerFolder\MyWordFil... string text = TextBox2.Text; // Put it in try-catch finally :) FileStream fs = File.Create(path); fs.Close(); StreamWriter sw = new StreamWriter(path); sw.Write(text); sw.Close(); ......

Posted On Saturday, October 8, 2005 8:12 AM

Accessing different controls inside the GridView control
Some developer emailed me and asked that how can he extract TextBox text when the TextBox is inside the GridView control. So, I implemented few lines of code to access DropDownList, TextBox and also ListBox which are inside the GridView control. First you need to populate the DropDownList and ListBox object. // This method also Populates the ListBox should be called PopulateDropDownAndListBox() :) public DataSet BindDropDownList() { SqlConnection myConnection = new SqlConnection(GetConnection... ......

Posted On Wednesday, October 5, 2005 3:06 PM

Code Generation in .NET using XSLT
I spent my sunday learning about Code Generation using XSLT. Lot of times we write repetitive code. This mainly includes creating entity classes. With code generation you can develop a template which writes code for you. In other way Code Generation means code that writes code . I wrote a very simple template which is used to make entity classes. Its not perfect design but you can get idea how it works. The xml file acts as the container where you tell the code generator what fields, methods ,properties ......

Posted On Monday, October 3, 2005 11:59 PM

Remote Scripting Caching Problems (AJAX)
AJAX is on my mind for quite some time now. I was implementing a functionality just like google suggest using AJAX.NET library when I ran into an interesting problem. Basically I have a method named FillList this method is marked with [Ajax.Method] attribute and hence has the power of being called from the client side. FillList method in turn calls GetDataSet method which returns the DataSet. Here is the implementation of the GetDataSet method. private DataSet GetDataSet() { DataSet ds = null; string ......

Posted On Saturday, October 1, 2005 10:18 PM

Google Suggest like feature using AJAX
I cranked up some code to make a google suggest like functionality using AJAX. Check out the image below: Although its not perfectly working but you can get an idea how the things work and you can enhance it. Here is the JavaScript code: <script language = "javascript"> function GetWords(pressevent,myVal) {var charCode = (pressevent.which) ? pressevent.which : (event.keyCode);// Check for the enter keyif(charCode!= 13) { ForumsQuestions.FillList(my... if(charCode == 32) { ......

Posted On Saturday, October 1, 2005 8:21 PM

Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net