Archive for April, 2008

How do I draw a box with CSS?

Tuesday, April 15th, 2008

To draw a box of a fixed shape all you need to do is specify the width and height of the area.You can then add padding and border to your box which will surround your content.
This code has produced green box
<style type=”text/css” media=”screen”>

.box {
background:#829900;
color:#fff; padding: 5px;
height: 340px;
width: 340px;
margin-top: 5px;
margin-right: auto;
margin-bottom: 5px;
margin-left: auto;
}
</style>

<div class=”box”>
</div>
f you don’t know the size of the content you can always set the width and height to auto so that the box expands and shrinks as required.

Posted by Mahesh ( Tryangled )

Passing Data one page to another page in ASP.NET?

Saturday, April 12th, 2008

we can only retrieve the values of the web form objects using the Request object. But what if we need to retreive the entire object from a different aspx page. In Classic ASP, passing an entire object from one page to another was possible with the help of either Session Objects or Application Object or we need to implement a custom way to transfer objects between ASP
pages.

Assume that, we have a page called source.aspx with one textbox and a button. When we click on the button, we are going to invoke a different page called destination.aspx. Our aim is to retrieve the entire texbox object from the destination.aspx.

Content of source.aspx
<%@ Page Language=”vb” Classname=”Source” %>
<script language=”VB” runat=”server”>
Sub Transfer(sender As Object, e As EventArgs)
Server.Transfer(”destination.aspx”)
End Sub

Public ReadOnly Property GetFirstname() As String
Get
Return txtFirstName.Text
End Get
End Property

Public ReadOnly Property GetFirstnameObj() As System.Object
Get
Return txtFirstName
End Get
End Property
</script>

Content of Destination.aspx
<script language=”VB” runat=”server”>
Sub Page_Load(sender As Object, e As EventArgs)
Dim objSource As source
objSource = CType(context.Handler, source)
Response.Write(”First Name is : ” & objSource.GetFirstnameObj.text & ”
“)
Response.Write(”ForeColor is : “)
Response.Write(objSource.GetFirstnameObj.ForeColor)
Response.Write(”
BackColor is : “)
Response.Write(objSource.GetFirstnameObj.BackColor)
End Sub
</script>

Posted by Mahesh ( Tryangled )

Merging two Datasets into a single Datagrid in ASP.NET?

Saturday, April 12th, 2008

Merge is one of the method of Dataset. The merge feature is basically used in applications where the concept of Master and
Transaction table exists.we need to have the following pre-conditions.
Pre-conditions for displaying two datasets in a single datagrid.
1) The primary thing is that, both all the columns specified in the datagrid must be present in both datasets.
2) The data type of all columns in the datasets must be same.
3) Also the column name should match.
Sub BindGrid()
Dim myConnection as New SqlConnection (strConn)
Dim DS1 As DataSet
Dim DS1 As DataSet
Dim MyCommand As SqlDataAdapter
MyCommand = new SqlDataAdapter(”exec s_get_table1″, MyConnection)
DS1 = new DataSet()
MyCommand.Fill(DS1, “MyTable”)
MyCommand = new SqlDataAdapter(”exec s_get_table2″, MyConnection)
DS2 = new DataSet()
MyCommand.Fill(DS2, “MyTable”)
ds1.merge(ds2)
MyDataGrid.DataSource=DS1.tables(0).DefaultView
MyDataGrid.DataBind()
End Sub

Posted by Mahesh ( Tryangled )

How to export data in Datagrid on a webform to Microsoft Excel?

Saturday, April 12th, 2008

Two techniques for exporting the data in the DataGrid:

* Using the Excel MIME Type (or Content Type)

With server-side code, you can bind the DataGrid to your data and have the data open in Excel on a client computer. To do this, set the ContentType to application/vnd.ms-excel. After the client receives the new stream, the data appears in Excel as if the content was opened as a new page in the Web browser.

* Using Excel Automation

With client-side code, you can extract the HTML from the DataGrid and then Automate Excel to display the HTML in a new workbook. With Excel Automation, the data always appears outside the browser in an Excel application window. One advantage to Automation is that you can programmatically control Excel if you want to modify the workbook after the data is exported. However, because Excel is not marked as safe for scripting, your clients must apply security settings in the Web browser that allow Automation.

Posted by Mahesh ( Tryangled )

How to display a Tooltip when hovering over the Header sort link of the DataGrid?

Saturday, April 12th, 2008

protected void ItemDB (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
for(int i=0 ;i<= e.Item.Cells.Count -1;i++)
{
e.Item.Cells[i].ToolTip = “This is Column ” + i.ToString();
}
}

Posted by Mahesh ( Tryangled )

How to display multiple dates selected in Calendar Control in asp.net?

Saturday, April 12th, 2008

Set the SelectionMode property of Calendar Control to DayWeek/ DayWeekMonth.
Code for the OnSelectionChanged as follows:

string strval=”" ;
foreach (DateTime day in Calendar1.SelectedDates)
{
strval += (day.Date.ToShortDateString() + “<br>”);
}
Response.Write(strval);
}

Posted by Mahesh ( Tryangled )

how to Call a Parameterized Stored Procedure by Using ADO.NET and Visual C# .NET?

Thursday, April 10th, 2008

There are several ways to use ADO.NET to call a stored procedure and to get
back return values and return parameters, including:

•Use a DataSet object to gather the returned rows and to work with these rows in addition to the return values and the return parameters.
•Use a DataReader object to gather the returned rows, to move through these rows, and then to gather return values and return parameters.
•Use the ExecuteScalar method to return the value from the first column of the results’ first row with the return values and the return parameters. This is most useful with aggregate functions.
•Use the ExecuteNonQuery method to return only the return parameters and the return values. Any returned rows are discarded. This is most useful for executing action queries.

Posted by Mahesh ( Tryangled )

What is a relay server?

Thursday, April 10th, 2008

A relay is a service that allows you to send email. It is usually a full fledged mail server, or can be a specialized SMTP Service. Some examples of a mail server include Microsoft Exchange, IMail by IPSwitch, or Mail Enable by Mail Enable. An example of a SMTP service is the SMTP Service installed that can be installed with IIS. SWM sends email to a relay server, and the relay server is responsible for delivering the email to the final destination. When sending email to a relay server, you must have protocol permissions to use that server. Because of SPAM problems, relay servers are normally locked down, either by IPAddress or by some type of username/password authentication. Relaying errors are the most common problems when programmatically sending emails. If you ever see an exception that reads something like “550 Permission Denied”, this is usually a relay error, and you need to talk to your mail server administrator about proper permissions.

Posted by Mahesh ( Tryangled )

Nested Master Pages in ASP.NET?

Wednesday, April 9th, 2008

You can write a content page that is itself a master page, allowing an arbitrarily deep nesting of master pages. This technique can be useful when your application is broken into sub-applications that need to inherit a common branded look but still be able to define their own customized layout template within the brand. The following listing shows a master page that would serve as a content page for our first master page example.

<%@ Master Language=”VB” MasterPageFile=”~/try.master”
CodeFile=”trychild.master.vb” Inherits=”trychild” %>
<asp:Content ID=”Content1″ ContentPlaceHolderID=”mainContent” runat=”Server”>
<div>
<asp:ContentPlaceHolder ID=”main1″ runat=”server” />
</div>
<div>
<asp:ContentPlaceHolder ID=”main2″ runat=”server” />
</div>
</asp:Content>

<asp:Content ID=”Content2″ ContentPlaceHolderID=”sideContent” runat=”Server”>
<asp:ContentPlaceHolder ID=”side1″ runat=”server” />
</asp:Content>

Notice we must obey the rules for a content page in this master page, that is, we can only define content inside of Content controls. The ContentPlaceHolders inside of these controls can then be filled in with web forms addressing the IDs of the nested master page. A web form cannot reach the ContentPlaceHolders in the master page above it’s own master page.

<%@ Page Language=”VB” MasterPageFile=”~/nested/otcchild.master”
AutoEventWireup=”false” CodeFile=”Default.aspx.vb”
Inherits=”_Default” title=”Untitled Page” %>
<asp:Content ID=”main1″ ContentPlaceHolderID=”main1″ Runat=”Server”>
<h4>Content1</h4>
</asp:Content>
<asp:Content ID=”main2″ ContentPlaceHolderID=”main2″ Runat=”Server”>
<h4>Content2</h4>
</asp:Content>
<asp:Content ID=”side1″ ContentPlaceHolderID=”side1″ Runat=”Server”>
<h4>Content3</h4>
</asp:Content>

Master Pages and Configuration
There are three ways to associate a web form with a master page. You can use the Master attribute in the @ Page directive, and you can write to the MasterPageFile property in the PreInit event or earlier. We’ve seen examples of both of these techniques. Any web form using the Master attribute of the @ Page directive or setting the MasterPageFile property programmatically will override the web.config settings.
We can also assign a default master page for all web forms in a site in our web.config file using the <pages> element. An example excerpt from web.config is shown below.
<configuration>
<system.Web>
<pages master=”try.master” />
</system.Web>

</configuration>

Posted by Mahesh ( Tryangled )

How to Add google map in your site using asp.net?

Wednesday, April 9th, 2008

using following steps to add google map in your site.

1. Get a Google Maps API key from here:
http://www.google.com/apis/maps/

2. Download the SubGurim wrapper dll from here:
http://en.googlemaps.subgurim.net/descargar.aspx
3. Unzip it, and put it in your \bin directory
4. Add it to your toolbox by
Tools -> Choose Toolbox Items -> Browse -> Select the .dll file -> OK
GMap will now be in the ‘Standard’ area of your Toolbox.
5. Add a new webpage.
6. Drag the GMap from the toolbox onto the page. A new instance of the GMap will appear on the page, with the name ‘GMap1′
7. Add the following lines to your web.config file:

<appSettings>
<add key=”googlemaps.subgurim.net” value=”YourGoogleMapsAPIKeyHere” />
</appSettings>

Dim sStreetAddress As String
Dim sMapKey As String = ConfigurationManager.AppSettings(”googlemaps.subgurim.net”)
Dim GeoCode As Subgurim.Controles.GeoCode
sStreetAddress = “100 Russell St. Melbourne. VIC. 3000. Australia”
GeoCode = GMap1.geoCodeRequest(sStreetAddress, sMapKey)
Dim gLatLng As New Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng)
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal)
Dim oMarker As New Subgurim.Controles.GMarker(gLatLng)
GMap1.addGMarker(oMarker)

Posted by Mahesh ( Tryangled )