NinethSense oWnZ mE!: Praveen’s drawing book

Choose a Topic:

Fri
18
Apr '08

DataSets vs. Collections

There is a good article on DataSets vs. Collections by Dino Esposito

If you read this article, you will start using (Generics) Collections instead of DataSet/DataTable for database access. :)


Here is the URL: http://msdn2.microsoft.com/en-us/magazine/cc163751.aspx
Mon
7
Apr '08

C# & Visual Basic Language Specification

C# 3.0 Language Specification Word Document can be downloaded at http://download.microsoft.com/download/9/5/0/9503e33e-fde6-4aed-b5d0-ffe749822f1b/csharp%203.0%20specification.doc

Same way, you can download Visual Basic 9.0 Language Specification at http://go.microsoft.com/fwlink/?LinkID=102846
Tue
11
Dec '07

DotNetNuke SlideShow Module

I developed a slideshow module for a DotNetNuke some days back. This is a simple module which fetches files from a folder specified and displays with fade effect.

You can freely download the DNN SlideShow module from here

You can see a demo here
Tue
9
Oct '07

How to display string in webBrowser Control

DocumentText property of web browser control lets you dynamically display html text.

Simple -

webBrowser1.DocumentText = “<b style=’color:red’>P</b>ra<b>V</b>ee<u>N</u>”;
Wed
26
Sep '07

Reorder listbox items with JavaScript and ASP.NET

Default.aspx:
 
< %@ Page Language=“VB” AutoEventWireup=“false” CodeFile=“Default.aspx.vb” Inherits=“_Default” ValidateRequest=“false”  %>
 
< !DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
 
<html xmlns=“http://www.w3.org/1999/xhtml” >
<head id=“Head1″ runat=“server”>
    <title>Untitled Page</title>
    <style type=“text/css”>
	#lstWishList {
		background-color:lightgrey;
		font:10px notmal arial;
		overflow:visible;;
	}
	
	#divNumbers {
		font:10px notmal arial;
		line-height:13px;
	}
	.imgbutton {
		cursor:pointer;
	}
</style>
<script language=“javascript”>
 
	function LoadNumbers() {
		lst = document.getElementById(“lstWishList”);		
		lst.size = lst.options.length;
		lstNumbers = document.getElementById(“lstWishListNumbers”);		
		div = document.getElementById(“divNumbers”);
		s = “”;
		for (i=1;i<lst .length+1;i++) {
			s += i+“<br>”;
		}
		div.innerHTML = s;
	}
	function ProcessUp(upordown) {
	    if (lst.selectedIndex < 0) return;
		v = (upordown==‘up’)?1:-1;
		lst = document.getElementById(“lstWishList”);
		oldindex = lst.selectedIndex
		newindex = lst.selectedIndex-v
		if (newindex &lt;0 || newindex > lst.options.length-1) return;
		
		
		temp = lst.options[oldindex].text;
		tempv = lst.options[oldindex].value;
		
		lst.options[oldindex].text = lst.options[newindex].text;
		lst.options[oldindex].value = lst.options[newindex].value;
 
		lst.options[newindex].text = temp;
		lst.options[newindex].value = tempv;
		
		lst.selectedIndex = newindex;
	}
	
	function ProcessRemoval() {
	    if (!confirm(“Are you sure you want to remove this item?”)) return;
	    lst = document.getElementById(“lstWishList”);
	    
	    for (i=0;i</lst><lst .options.length;i++) {
	        if (lst.options[i].selected)
	            lst.remove(i);
	    }
	    LoadNumbers();
	}
	
	function PopulateHiddenField(){
	    hid = document.getElementById(“hidListItems”);
	    lst = document.getElementById(“lstWishList”);
	    s = “”;
	    for(i=0;i<lst.options.length;i++) {
	        s += lst.options[i].value + “|” + lst.options[i].text;
	        if (i+1 != lst.options.length) s+= “~”;
	    }
	    hid.value = s;
	}
 
</script>
    
</lst></script></head>
<body>
    <form id=“form1″ runat=“server”>
    <table cellpadding=0 cellspacing=0>
	<tr>
		<td colspan=3 style=“border:solid 1px black”>
<table><tr><td valign=“top” style=“background-color:lightgrey;”>
<div id=“divNumbers”>test</div>
</td><td>
<asp :ListBox ID=“lstWishList” runat=“server”></asp>
</td></tr></table>
</td>
</tr>
 
<tr><td align=center valign=middle><img src=“up.gif” class=“imgbutton” border=1 onclick=“ProcessUp(’up’)”/></td>
<td align=center valign=middle><img src=“down.gif” class=“imgbutton” border=1 onclick=“ProcessUp(’down’)”/></td>
<td align=center valign=middle><img src=“x.gif” class=“imgbutton” border=1 onclick=“ProcessRemoval()”/></td>
</tr>
 
</table>
        <br />
        <asp :Button ID=“Button2″ runat=“server” Text=“Submit Changes” OnClientClick=“PopulateHiddenField()” /><br />
        <br />
        <asp :HiddenField ID=“hidListItems” runat=“server” />
        <br />
        <hr />
        &nbsp;<br />
        Preview of datatable dt :
        <br />
        <br />
        <asp :GridView ID=“GridView1″ runat=“server”>
        </asp>
        
    </form>
</body>
</html>
<script language = “JavaScript”>
	LoadNumbers();
</script>

Default.aspx.vb:
 
Imports System.Data
 
Partial Class _Default
    Inherits System.Web.UI.Page
    Dim dt As New DataTable
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
 
        ‘ Fill sample data in listbox
        Dim dr As DataRow
        dt.Columns.Add(“id”)
        dt.Columns.Add(“title”)
        If (Not IsPostBack) Then
            dr = dt.NewRow() : dr(“id”) = “33″ : dr(“title”) = “My Title” : dt.Rows.Add(dr)
            dr = dt.NewRow() : dr(“id”) = “13″ : dr(“title”) = “My Title blah” : dt.Rows.Add(dr)
            dr = dt.NewRow() : dr(“id”) = “1523″ : dr(“title”) = “asd asdf asda” : dt.Rows.Add(dr)
            dr = dt.NewRow() : dr(“id”) = “1723″ : dr(“title”) = “My Title asdf asdasdasd” : dt.Rows.Add(dr)
            dr = dt.NewRow() : dr(“id”) = “123″ : dr(“title”) = “2222 My Title” : dt.Rows.Add(dr)
            dr = dt.NewRow() : dr(“id”) = “1123″ : dr(“title”) = “122222 My Title” : dt.Rows.Add(dr)
 
            lstWishList.DataValueField = “id”
            lstWishList.DataSource = dt
            lstWishList.DataTextField = “title”
 
            lstWishList.DataBind()
        End If
 
    End Sub
 
 
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
 
        ‘ You will get list items as a delimeted string in hidden field - hidListItems.Value - re-fill datatable dt
 
        dt.Clear()
        Dim s() As String = hidListItems.Value.Split(“~”)
        Dim i As Integer
        Dim j As Integer
        Dim dr As DataRow
        For i = 0 To s.Length - 1
            Dim s1() As String = s(i).Split(“|”)
            dr = dt.NewRow() : dr(“id”) = s1(0) : dr(“title”) = s1(1) : dt.Rows.Add(dr)
        Next
        lstWishList.Items.Clear()
        lstWishList.DataValueField = “id”
        lstWishList.DataSource = dt
        lstWishList.DataTextField = “title”
 
        lstWishList.DataBind()
 
        ‘Now you have re-ordered values in datatable dt - use it to update database.
        ‘Like - delete all the wishlist items of this customer, then add this dt list 
 
        ‘data preview in grid view
 
        GridView1.DataSource = dt
        GridView1.DataBind()
    End Sub
End Class
Tue
19
Jun '07

Programatically get list of Installed Programs

To get the list of installed software programs in a machine use this code:


 RegistryKey rk = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, “pvn”);
            RegistryKey rkprograms = rk.OpenSubKey(@“Software\Microsoft\Windows\CurrentVersion\Uninstall”);
            foreach (string s in rkprograms.GetSubKeyNames())
            {
                listBox1.Items.Add(s);
            }



Namespace: Microsoft.Win32
Fri
1
Jun '07

Download any file from ASP.NET

You know, some formats (txt, gif etc.) will be shown on the browser rather than downloading when we try. Below is the script which will help you to download any file.


 
        Response.Clear();
        Response.AddHeader(“Content-disposition”, “attachment; filename=<filename>”);
        Response.WriteFile(“C:\</filename><filename>”);
        Response.End();
</filename>


The same logic is used in any server language.
Wed
23
May '07

Use Threads and Build Asynchronous Handlers in Your Server-Side Web Code

Fortunately for developers, threading in ASP.NET is a lot easier than it was in ASP. In this article, the author takes a look at threading in the ASP.NET HTTP pipeline, and explains how threads are managed efficiently without the involvement of the developer. The article considers how the common language runtime threadpool is used by ASP.NET to service requests, looks at the pooling mechanisms used for handlers, modules, and applications, and covers both IIS 5.0 and IIS 6.0 and how they differ in their approach to request processing and thread allocation. Finally, how and when to use asynchronous handlers is discussed for developers who still need to use threads in their own applications.


Check this: http://msdn.microsoft.com/msdnmag/issues/03/06/Threading/
Tue
22
May '07

Choosing the right programming language

My students used to ask me “which programming language is the best?” and “which programming language I must learn?”. But the truth is – one cannot give an accurate answer for this. If somebody answers to this question simply - like C++ or Java, I will say he is a frog living inside a well. He may be giving this answer from his experience and knowledge, which is very less.


Check my latest article at : http://ninethsense.com/content/view/51/55/
Wed
23
Aug '06

ADO.NET Passing parameters to SQL queries

 
 Dim param(0) As ParameterBuilder
 
param(0) = New ParameterBuilder(“@CustomerID”, DbType.UInt32)
Dim CustomerID As Integer = CInt(InputBox(“Enter Customer ID”))
param(0).Value = CustomerID
 
Dim sql As String = “DELETE FROM Customers WHERE CustomerID=@CustomerID”
The CodeProject Microsoft Developer Network Official ASP.NET Forums Microsoft .NET Framework Community Microsoft Most Valuable Professional Kidoos forums Microsoft Visual Studio Developer Home Professional Information Technology Solutions Microsoft Research Home Trivandrum Microsoft Users Group Community Website