Monday, May 31, 2004

 

Interoperability in .NET

There are lot of things related to Interoperability.
Here i am giving compiled links with some introduction about those links that i have .
I think it covers all about Interop in .NET realted to Software Development scenario only.

Interop in .Net

1. COM -> .NET and .NET ->COM
http://www.codeproject.com/dotnet/COM_DOTNET_INTEROP.asp
This article provides a technical overview of .NET and COM interoperability with good diagrams. This shows what happens and how you need to manage interop inside and in-depth in this scenario.
http://www.csharphelp.com/archives2/archive437.html
Using COM components in .NET framework
Good link that explains with examples and source is also there as .zip
http://www.codeproject.com/dotnet/nettocom.asp
Creating a CCW for COM enabled non .NET applications.
A method of calling .NET functions from a COM enabled non .NET environment through a COM callable wrapper
This is very good article with C# and VB.NET code sample and it explains how to do that using code as well as using some tools.

2. PLATFORM INVOKE
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vcwlkPlatformInvokeTutorial.asp
Everything about P/Invoke on MSDN tutorial
http://www.codeproject.com/dotnet/PInvoke.asp
With C# and VB.NET code sample
http://www.gotdotnet.com/team/clr/bcl/TechArticles/TechArticles/PInvokeHelp/FAQ.aspx
All about PINVOKE - help you to cover each aspect related to P/Invoke

3. CLR and JVM (Interop between .NET and JAVA)
Two possible ways,
3.1 Web services
This is the hottest topic now a day in IT industry because of its flexibility and its power.
There are lot of tutorials on net that how to develop web services in .net but our purpose is the interop issue so i am giving here some sites that helps in interop with web services.
www.ws-i.org
Most important site that gives all about interop for web services as this is dedicated organization for interop issues in web services.
It provides a Basic Profile (standard/specifications) that covers more than 150 interop issues addressed in web service development related to interoperability.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsvcinter/html/WSI-BP_MSDN_LandingPage.asp
This is Microsoft link that provides a very good article regarding Building Interoperable Web Services in .net - gives everything enough.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsvcinter/html/globalxmlwebsrvinterop.asp
XML Web Services Interoperability Resources
3.2 Third-party tools
I didn’t use it so don’t know much but have few links,
http://www.borland.com/janeva/
Borland's Janeva that can be use for CLR and JVM interop
http://www.theserverside.net/talks/library.tss#NatarajanJaneva
http://www.theserverside.net/talks/library.tss#SimonGuest
This may help using Janeva
http://caffeine.berlios.de/site/resources/interop.html
Very good tool - Caffeine - that you can use in this scenario - it helps in Interoperability Solutions for the Java and .NET platforms with examples and diagrams
http://j-integra.intrinsyc.com/ja.net/doc/whitepaper/
http://j-integra.intrinsyc.com/ja.net/doc/lifetime_management.html
Ja.Net - another third-party tool
http://www.asahi-techneion.co.jp/system/Intrisyc/Intri_Ja_Det.htm
Other ja.net link
http://www.devx.com/interop/Article/19945
Calling Java Classes Directly from .NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/swingwinforminterop.asp
Displaying .NET Windows Forms from Java SWING

Extra links for interop:
http://www.dotnetinterop.com/samples.aspx
Few articles with samples for various issues in interop like P/Invoke, Component Services, Windows Shell, and IE and Web browser control
http://www.microsoft.com/technet/itsolutions/interop/default.mspx


 

.Net Application Architecture

Some good links on Application Architecture in .net
Application Architecture for .NET: Designing Applications and Services
This guide provides design-level guidance for the architecture and design of .NET Framework applications and services built on Windows 2000 and version 1.0 of the .NET Framework. It focuses on partitioning application functionality into components, walks through their key design characteristics, explains how security, management and communication apply to each layer, and provides information on how the components should be deployed.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/distapp.asp?frame=true

Application Architecture center at MSDN
All about App. Architecture...
http://msdn.microsoft.com/architecture/application/default.aspx
Application Architecture home at GOTDOTNET
http://gotdotnet.com/team/architecture/application/

Architecture related Sites:
http://www.zifa.com/
http://www.metagroup.com/products/insights/eas_1_sco.htm
http://www.ewita.com/
http://www.wwisa.org/
http://www.eacommunity.com/
http://www.sei.cmu.edu/ata/ata_init.html
http://www.zapthink.com/
http://www.opengroup.org/togaf/
http://www.theserverside.net/
http://www.cbdiforum.com/index.php3


Tuesday, May 25, 2004

 

ASP.NET page fire automatically at defined intervals

In your Page_Load method add the following line:

Response.Write("<META HTTP-EQUIV=Refresh CONTENT='10; URL='>")

The page will refresh in 10 milliseconds
If you specify a WRL then the page will redirect to another page specified in the URL.
 

Diff between DCOM & Remoting

Both DCOM and Remoting enable interprocess communication between processes, but:

.NET Remoting is more flexible
More activation and deployment options
.Net Remoting uses leases as opposed to pinging
Less traffic on the wire
.NET Remoting is object oriented
Lease expirations, etc. are customizable via inheritance and overloading
.NET Remoting has no mandated security support
More options, more flexible

For articles related to the same, the best place to search will be the MSDN site or even MSDN for Visual Studio .NET 2003 edition.


Further there is an interesting article
This will give you the exact picture of DCOM and .NET Remoting. This article has been written by David Chappell . The person who done great things in COM (Inside COM) and mnay more.

So he is simply the best.
http://www.chappellassoc.com/articles/article_informIT_DCOM_dead.html


 

Visual Inheritance in VB.Net

Inheritance

Before getting into the Visual Inheritance, we should know Inheritance and how it is done in VB.Net.

Inheritance is the concept that a new class can be based on an existing class, inheriting the interface and functionality from the original class.

Inheritance, for instance, is also sometimes referred to as generalization. This is because the class from which we are inheriting our behavior is virtually always a more general from of our new class.

Consider the following example,
We have a class called “Vehicle” which contains properties like “no of wheels”, “how many people can sit”.
Now consider the class “Bi-Cyle”, “Motor Cycle”, “Car” etc., Which all have the above mentioned properties, many other common properties and some properties on their own (for eg., Car will have the “type of fuel” property). All these classes are basically “Vehicles”.

Inheritance makes it very easy to create classes “Bi-cyle”, “Motor Cycle” and “Car” and so forth. We don’t have to redefine those properties for a “Car” to become a vehicle, it automatically gets any properties, methods and events from the original Person class.

The class from which the properties and methods are inherited is called a base class. It is also often referred to as a super class or a parent class. And the class which inherits the base class is called a Derived class or a sub class. It is also referred as the derived class.

“is-a” Relation ship

Inheritance relationship is also referred to as an “is-a” relationship. When we create a “Car” class that inherits from a “vehicle” class, Then “Car” class is a “vehicle”.

Forms

Now, just for sometime we will move to the VB6.0 where many of us would have worked on the form (VB6.0 Form), If we pay more attention and examine it carefully, we can realize that both a form and a class are one and the same thing, when compared to classes forms have added feature of a user interface. VB6.0 has done a wonderfully job of hiding it.

Not only that, we design our form in VB6.0 by putting some Command Buttons, Text boxes and what not. Have you ever taken some time and thought where am I declaring the controls in the code ? You magically get a variable defined and instantiated for you. VB6.0 writes the code and hides it from the user.

If you are really interested in knowing what is happening behind the scenes in VB6.0, just the do the following steps carefully, you yourself will find all those magics done carefully in VB6.0, If you are not really not interested just proceed with the remaining part of the document

• Create a new VB6.0 Project
• By default on form will be added
• Design your form and write some code(for eg., put two text boxes and place of command button, in the command button click event the write the code to display as message box displaying the sum of two numbers entered in the textboxes)
• Now save the project
• You will be getting three files one is your project, Source safe file and other one is the form file
• Now open the .frm file in any of the text editors, you can see the entire code written in that file
• You can see the entire code cleanly written and kept hidden from you when viewed in the VS IDE.
• You can see your Textboxes, command button and form properties defined there. Not only that the code which you have written.


In Vb.net, all the forms are now true classes, and it’s abundantly obvious. There are no more secrets going on behind the scenes. All the properties are defined directly in code.

In Vb6.0, forms were saved as .frm files, But in VB.Net the forms are classes, they are stored in the extension .VB just like conter classes.

By inheriting from System.Windows.Froms.Form, any class automatically gets all the properties methods, and events that a form based on Windows forms is supposed to have.


Note:
Create a new form in VB.Net, get into the coding window you can see the declaration of the class like this.

Public class formName inherits System.Windows.Forms.Form




Visual Inheritance

Now, we have discussed about the Inheritance. We will see how this inheritance can be used to help us.

.Net fully utlises the OOPs concept fully.

As we discussed earlier, a form in .Net is nothing but a class that inherits System.Windows.Forms.Form class. We know that Inheritance defines a “is a” relationship between the derived and super class.

So class does not have to inherit directly from the system.window.forms.form class inorder to become a form. It can become a form by inheriting from another form, which itself inherits from System.Windows.Forms.Form. By doing so, controls originally placed on one form can be directly inherited by a secord form. Not only the design of the original form inherited, but also any code associated with these controls. This method of creating a form is called as the Visual Inheritance.

It can be done in Two ways.

1. Create a class and inheriting the form
• Create a Form from which the other form is to be inherited.
• Add a new class and inherit the form using the inherits keyword

2. Using the Inheritance Picker.
• Design the form.
• Right Click on the project and choose Add Inherited Form.
• Which open the Inheritance Picker from which the user can pick the form from which it has to inherit
• Note that the from must be compiled into either an .EXE or a DLL, Before it can be used by the Inheritance Picker.

Advantages of Visual Inheritance

Visual Inheritance provides lot of advantages
• Code Reusability
• Defining the UI once and using it in the other forms
• Modifying the UI is very simple
• Doesn’t require the Code to be re-compiled once again when the UI is changed

Example

Consider a application where we want all the forms in the project to have a logo on the top left corner and a label displaying a company name and Date & Time running in the right side of the form.

Without Visual Inheritance we need to design and write code in all the form inorder to get the following functionality.

To avoid that we will be create a form with all these functionalities and extends that form to all other classes.

Step 1: Defining the Template Form

• Open a New Windows Application Project. By default one from will be there rename the form to TemplateForm
• Add the following controls, add one picture box, Three Labels and name them us lblcompanyname, lbldate and lbltime
• And one timer, set the interval property to 1000 and set enable property as true
• Add the following code in the Form Load Event (Code to display the company name in the lable)
LblCompanyName.Text = Me.Text
• Add the following code in the Timer Tick event
lbltime.Text = Format(Now, "hh:mm:ss tt")
lblDate.Text = Format(Now, "dd/MM/yyyy")
• Build the project

Step 2: Using the Visual Inheritance

• Right Click on the project and select ADD  ADD Inherited Form
• Type the form name in the Add new Item window and click open
• Inheritance Picker window will appear as shown below


• If the template form is in the current project, slected the form form the list provided and click ok
• Or else click browse to selected the dll containing the form. On selected the dll, the window will display all the classes available in the dll
• Select the form and click ok
• On Clicking ok we will be getting a form with the same design we did for the template form
• But we can find a small difference, in the all the controls that belong to the parent class contains an arrow mark at the top, denoting that they are inherited components
• Note that all the properties of the components are readonly, we can’t change any property, we will see how to over come that in our proceeding discussion.
• Now, set the start up form by clicking on the project and selecting the start up form.
• Changet the Form Text Property.
• And run the form
• You could see the timer running and the Company name changed.


Accessing the Controls from the Inherited form

As we all know about the scope of a object. So by changing the scope of the controls in the Template form we can acces the controls in the Inherited form also.

The following table lists all the available scope options:

Scope Description
Public Available only to code within our class
Protected Avaiable only to classes that inherit from our class
Firend Available only to code within out project/component
Protected Frient Available to classes that inherit from our class and to code within our project/component. This is a combination of Protected and Friend
Public Avaiable to code outside our class


Changing the UI of the Base Form

Changing the UI of the form is very simple.

If the Base Form is in the same project then changing the form and compiling the form is enough. It make all the changes in the other forms.

If the base form is derived from the other forms cantained in a dll, then make the changes in the master from and build the dll. And replace that dll with the old one.

 

Translation

This is a pretty simple job, and can be broken down into the following subtasks:

Get text for translation and encode it into a HTTP POST request
Send the data to the web server, acting in effect as a .NET web browser
Read the response back into a big string
Remove all the HTML and formatting and send the raw translated string back to the client.
[WebMethod] public string BabelFish(string translationmode, string sourcedata) { }
readonly string[] VALIDTRANSLATIONMODES = new string[] {"en_zh", "en_fr", "en_de", "en_it", "en_ja", "en_ko", "en_pt", "en_es", "zh_en", "fr_en", "fr_de", "de_en", "de_fr", "it_en", "ja_en", "ko_en", "pt_en", "ru_en", "es_en"};
The code performs validation to check for a valid mode before passing it on to Babelfish. After that, we create a POST request. The syntax for a HTTP POST request looks something like this:

POST /babelfish/tr/ HTTP/1.0 Content-Type: application/x-www-form-urlencoded Content-Length: 51 lp=en_fr&tt=urltext&intl=1&doit=done&urltext=cheese
It's pretty simple, and if you want, you could use low-level sockets to write the data to the server. Microsoft provides some better ways to do this however, and so we use the HttpWebRequest class, which has lots of built-in features to make it easy to work with HTTP connections.

Uri uri = new Uri(BABELFISHURL); HttpWebRequest request = (HttpWebRequest) WebRequest.Create(uri); request.Referer = BABELFISHREFERER; // Encode all the sourcedata string postsourcedata; postsourcedata = "lp=" + translationmode + "&tt=urltext&intl=1&doit=done&urltext=" + HttpUtility.UrlEncode(sourcedata); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = postsourcedata.Length; request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)"; Stream writeStream = request.GetRequestStream(); UTF8Encoding encoding = new UTF8Encoding(); byte[] bytes = encoding.GetBytes(postsourcedata); writeStream.Write(bytes, 0, bytes.Length); writeStream.Close(); HttpWebResponse response = (HttpWebResponse) request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader readStream = new StreamReader (responseStream, Encoding.UTF8); string page = readStream.ReadToEnd();
We end up with a string containing the entire Babelfish page. As it stands, this is about 99% noise (HTML tags, Altavista information, etc.), and 1% the translation we were looking for. So we need a regular expression to find the translated text. By looking at the HTML page, you will find the translation is contained between:

translation here

So the required regular expression looks like this (note: while testing my regular expressions, I got lots of help from Regulator):

((?:.|\n)*?)

This will match the whole
...
string. This is a fairly complex regular expression, but basically, the . character matches everything, except for newlines, hence the (.|\n) pattern, which means any character (except newlines) or new lines.

The brackets create a matching group, meaning that the text within the brackets (namely the translation) will be put in its own group at index 1 (index 0 contains the whole match).

The ?: pattern suppresses grouping: () normally creates a matching group: in this case, we are only using the pattern to allow for line breaks in long translations.

Finally *? is a lazy regular expression, matching every character up to the first instance of
. (If I had used plain *, the expression would be greedy, and would chomp right up to the LAST
.)

Here's the code:

Regex reg = new Regex(@"
(.*?)
"); MatchCollection matches = reg.Matches(page); if (matches.Count != 1 || matches[0].Groups.Count != 2) { return ERRORSTRINGSTART + "The HTML returned from Babelfish " + "appears to have changed. Please check for" + " an updated regular expression" + ERRORSTRINGEND; } return matches[0].Groups[1].Value;
And subject to error checking, that's it!

Using it
Download the code, and unzip it somewhere. Add a virtual directory called Translation in IIS. Go to /translate.asmx and click Test, and enter some test data (say 'en_fr', and 'cheese'). If it works, you are ready to use it in your web and Windows Forms applications.

To use it in your app, add a Web Reference to the asmx, to the program you want to use it in; Visual Studio will create a proxy reference for you, which you can then use to perform translation.

Here's some sample code-behind:

namespace test
{
using System;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using localhost1; // assuming that's the reference generated
using System.Web.UI.HtmlControls;

///
/// Summary description for WebUserControl1.
///

public class WebUserControl1 : System.Web.UI.UserControl {
protected System.Web.UI.WebControls.DropDownList ddTranslationMode;
protected System.Web.UI.WebControls.TextBox txtText;
protected System.Web.UI.WebControls.Label lblTranslation;
protected System.Web.UI.WebControls.Button submitButton;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}

protected void submitButton_Click(object sender, System.EventArgs e)
{
string translationMode = this.ddTranslationMode.SelectedItem.Value;
string translationText = this.txtText.Text.Trim();
string translation = "";
try
{
Translate tr = new Translate();
translation = tr.BabelFish(translationMode,translationText);
}
catch (Exception exp)
{
translation = "There was an error accessing the server: " + exp.Message;
}
this.lblTranslation.Text = translation;
}
}
}

 

tips and tricks ...

Check loads and loads of tips and tricks ...

http://www.geocities.com/s_kamal_kannan/asptips/ for ASP.Net
http://www.geocities.com/s_kamal_kannan/SQL/ for SQL
http://www.geocities.com/s_kamal_kannan/xml/ for XML


Creating Wizards - Property Sheets, Property Pages

http://www.dotnet247.com/247reference/msgs/21/106137.aspx
http://www.codeproject.com/cs/miscctrl/ak_wizard.asp

 

Interview Questions

Interview Questions
1. C/C++ Interview Questions:

1. http://www.softcorp.demon.co.uk/c++2.html
2.
http://www.onesmartclick.com/interviews/interviews-programming.html
3.
http://www.cpuniverse.com/newsite/archives/1999/mar/c++.html
4. http://www.oneparticularharbor.net/sam/interview.html
5.
http://www.acetheinterview.com/cgi-bin/qanda.cgi?action=topics number=5
6.
http://www.geocities.com/Athens/Agora/3027/work/interviewQuestions.html
7. http://www.moskalyuk.com/jobs/cpp_5.htm
8. http://www.moskalyuk.com/jobs/java_1.htm
9. http://www.cs.unc.edu/~scheib/work/questions/
10.

http://www.cis.temple.edu/~ingargio/cis307/assessment/intervie
ws.html
11.

http://www.geocities.com/SiliconValley/Park/1512/cpuz_l1.html

2. C/C++ Notes for Interviews:

1. http://leepoint.net/notes/cpp/
2. http://www.parashift.com/c++-faq-lite/
3. My Notes
4. http://cslibrary.stanford.edu/


3. Microsoft Interview Questions:

1. http://halcyon.usc.edu/~kiran/msqs.html
2.

http://www.4guysfromrolla.com/ASPscripts/PrintPage.asp?REF=/we
btech/012700-1.shtml
3.

http://www.sellsbrothers.com/fun/msiview/default.aspx?content=
question.htm
4.

http://www.acetheinterview.com/qanda/microsoft_interview.html
5.

http://bbs.mit.edu/cgi-bin/BBS0an?/groups/GROUP_3/JobHunting/I
nterview
6.

http://www.bucketobits.com/chris/programmerinterviewquestions.
html

4. Puzzles:

1. http://www.techinterview.org/archive/
2. http://puzzle.dse.nl/index_us.html
3.
http://www.chlond.demon.co.uk/academic/puzzles.html
4. http://pub13.ezboard.com/fvisualbasicexplorerfrm44

5. Operating Systems Notes:

1.
http://williamstallings.com/Extras/OS-Notes/notes.html
2.
http://www.ibilce.unesp.br/courseware/opsys/ostart.htm
3. http://www.cs.wisc.edu/~solomon/cs537/notes.html
4.

http://www.cs.wisc.edu/~bart/537/lecturenotes/titlepage.html

6. Win32 Tutorials:

1. http://www.winprog.org/tutorial/
2. http://www.gajits.com/win32.asp

7. Data Structure Notes:

1.

http://ciips.ee.uwa.edu.au/~morris/Year2/PLDS210/ds_ToC.html
2.

http://www.csl.mtu.edu/cs2321.rp/www/lectures/cs2321lectures.h
tm

8. Software Testing Notes:

1.

http://louisa.levels.unisa.edu.au/se1/testing-notes/testing.ht
m
2.

http://hebb.cis.uoguelph.ca/~dave/343/Lectures/testing.html
3. http://www.cee.hw.ac.uk/~air/se4/
4.

http://www.darkshire.org/~jhkim/programming/process/testing.ht
ml

9. Mathematical Puzzles

1. http://thinks.com/webguide/mathpuzzles.htm
2. http://www.syvum.com/teasers/
3. http://www.eduplace.com/math/brain/
4. http://www.brainbashers.com/
5. http://barryispuzzled.com/
6. http://www.braingle.com/

 

ComboBox in ASP.NET DataGrid

This step-by-step article describes one method that you can use to add a ComboBox control to a DataGrid control.

There are many ways to add a ComboBox control to a DataGrid control. Most of these methods involve using the ColumnStyles collection of the DataGrid. However, this article uses a simpler method, which is to add the drop-down ComboBox control to the Control collection of the DataGrid.

back to the top

Create the Sample
Follow these steps to create a new Visual Basic Windows Application project:


Start Microsoft Visual Studio .NET.


On the File menu, point to New, and then click Project.


In the New Project dialog box, click Visual Basic Project under Project Types, and then click Windows Application under Templates. By default, Form1 is added.


Drag a DataGrid control from the toolbox to Form1.


Add the following code to the top of the code window in the Declarations section of Form1.vb:


Imports System.Data.SqlClient
Imports System.Windows.Forms
Add the following code after the "Windows Form Designer generated code" section of the code window:


Public MyCombo As New ComboBox()
Dim con As New SqlConnection("server=myservername;uid=myid;pwd=mypassword;database=northwind")
Dim daEmp As New SqlDataAdapter("Select * From Employees", con)

Public ds As New DataSet()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler MyCombo.TextChanged, AddressOf Ctrls_TextChanged
'Fill ComboBox list.
MyCombo.Name = "MyCombo"
MyCombo.Visible = False
MyCombo.Items.Clear()
MyCombo.Items.Add("Sales Representative")
MyCombo.Items.Add("Inside Sales Coordinator")
MyCombo.Items.Add("Vice President, Sales")
MyCombo.Items.Add("Sales Manager")
MyCombo.Items.Add("Flunky")


daEmp.Fill(ds, "Employees")

'Set the RowHeight of the DataGrid to the height of the ComboBox.
DataGrid1.PreferredRowHeight = MyCombo.Height

DataGrid1.DataSource = ds

DataGrid1.DataMember = "Employees"
'Add ComboBox to the Control collection of the DataGrid.
DataGrid1.Controls.Add(MyCombo)
End Sub

Private Sub DataGrid1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles DataGrid1.Paint
If DataGrid1.CurrentCell.ColumnNumber = 3 Then
MyCombo.Width = DataGrid1.GetCurrentCellBounds.Width
End If
End Sub

Private Sub Ctrls_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs)
If DataGrid1.CurrentCell.ColumnNumber = 3 Then
MyCombo.Visible = False
If DataGrid1.Item(DataGrid1.CurrentCell) & "" = "" Then
SendKeys.Send("*")
End If
DataGrid1.Item(DataGrid1.CurrentCell) = MyCombo.Text
End If
End Sub

Private Sub DataGrid1_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
If DataGrid1.CurrentCell.ColumnNumber = 3 Then
MyCombo.Visible = False
MyCombo.Width = 0
MyCombo.Left = DataGrid1.GetCurrentCellBounds.Left
MyCombo.Top = DataGrid1.GetCurrentCellBounds.Top
MyCombo.Text = DataGrid1.Item(DataGrid1.CurrentCell) & ""
MyCombo.Visible = True
Else
MyCombo.Visible = False
MyCombo.Width = 0
End If
End Sub

Private Sub DataGrid1_Scroll(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Scroll
MyCombo.Visible = False
MyCombo.Width = 0
End Sub

Private Sub DataGrid1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.Click
MyCombo.Visible = False
MyCombo.Width = 0
End Sub
Modify the connection string as necessary for your environment.


Press F5 to run the project. Click one of the fields in the Title column in the DataGrid. Notice that the ComboBox control is located in the DataGrid.


Expand the ComboBox. Notice that a list of titles is displayed.

 

Confirm box in asp.net

Hi !

You can do this. Read the solution given below :

ASP.NET web forms provide a new programming model that eases many
development tasks. However, there is misconception amongst many programmers
that one should only use the server side model. In fact, most of the books
available today give emphasis on server side programming. This is natural as
any book will try to cover the new and exciting features of the technology
under consideration. However, many times business requirements call for
using traditional things like using JavaScript or using DHTML. This article
will illustrate one such scenario - Dialog Boxes. IE provides an easy way to
create modal browser windows via its object model. In this article I will
show you how to create dialog boxes using ASP.NET, JavaScript and IE object
model.

Sample Scenario
Consider a case where user is presented with a screen on which he is
supposed to enter customer ID or Customer Name. Now, under rich client
environment you can easily show a Grid or ListBox filled with available
customers and then user can select from the list. What about web browser?
This is where JavaScript and IE object model comes handy. IE provides
certain functions that allow you to show modal and modal-less dialog boxes.
We will now develop a sample pages using these techniques. You can actually
starting coding along with the explanation given below.

Creating the main form
For our example we will create a simple web form that contains a Label
(Label1), a Textbox (TextBox1) and two buttons (btnLookUp and btnSubmit).
Once you place above controls on your form add following JavaScript block in
the HEAD section of the web form.

<script>
function ShowDialog()
{
//declare a string variable
var retval="";

//show modal dialog box and collect its return value
retval=window.showModalDialog
('dialogboxhostframe.htm',window);

//check if user closed the dialog
//without selecting any value
if(retval!="" && retval!=null)
{
//fill the textbox with selected value
document.getElementById("TextBox1").value=retval;
}
}
</script>


This block consists of a function ShowDialog that actually displays a modal
dialog box to the user. The dialog box in turn contains the web form that
presents the list of customers. Please read the comments above to get idea
of what each line does. Note that we have given url as
'dialogboxhostframe.htm'. Why? If we display a web form directly in this
modal dialog box it opens up in a new window after being posted back. This
is irritating behavior and in order to overcome this we need to display the
web form as a part of FRAMESET.
We have created the function to display the dialog but when it will be
called? We want to invoke this dialog when user clicks on btnLookUp button.
We will now add a line of code in the Page_Load event that makes this
possible.

Private Sub Page_Load
(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.Load

btnLookUp.Attributes.Add("OnClick", "ShowDialog();")

End Sub

Here, we have added OnClick client side event handler to the attributes
collection of the button.
Creating the 'Dialog Box'

Now, we will design the web form that acts as 'dialog box' or 'selection
list'. Add another web form say DialogBox.aspx to your web application. Put
a ListBox (lstCustomers) and Button (btnClose)on it. Populate the list box
either with hard coded values or via data binding. In the HEAD section of
the form write JavaScript block as shown below:

<script>
function CloseWindow()
{
//set return value of the dialog box or dialog result
top.returnValue=
document.getElementById("lstCustomers").value;

//close the dialog window
window.close();
}
</script>


Above function will be called when user clicks the btnClose button. Note
that here we are closing the dialog box and setting return value of the
dialog box (also called as dialog result) to the selected value from the
list box. In the Page_Load of this web form add code that will attach this
function with the client side OnClick event of the btnClose.

Private Sub Page_Load
(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles MyBase.Load

btnClose.Attributes.Add("OnClick", "CloseWindow();")

End Sub

This code looks similar to the previous form but is used to close the dialog
box.
Creating frameset to host the 'Dialog Box'
As explained earlier we need to display our dialogbox.aspx as a part of
FRAMESET. So, create HTML page say dialogboxhostframe.htm. This HTML page
should contain a FRAMESET. One of the frames should point to dialogbox.aspx.
Following is a sample HTML markup:


<html>
<head>
<title>Header Frameset</title>
</head>
<frameset rows="0,*">
<frame name="header" src=""
scrolling="no" noresize>
<frame name="main" src="DialogBox.aspx">
</frameset>
</html>

That's it! You have successfully created a dialog box that will be displayed
in your ASP.NET web form. I have attached the sample source code too, for
your exercise.


Hope, this helps you out. And if any case, this don't you can again get back
to me.


!! Enjoy Coding !!

This page is powered by Blogger. Isn't yours?