Showing posts with label C#. Show all posts
Showing posts with label C#. Show all posts

Sunday, May 20, 2012

Google Maps JavaScript API v3 Example in asp.net

No comments:


<head runat="server">
    <title>Google Maps JavaScript API v3 Example in asp.net</title>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script>
    <script type="text/javascript">

        google.maps.event.addDomListener(window, 'load', initialize); //run when after page load
        var map;
        var markercode;
        var markermyLatlng;
        var markermyLatlngCount=0;

        function initialize() {
            var Lat=<%= dbLat %>;
            var Lon=<%= dbLon %>;
            var myOptions = {
                center: new google.maps.LatLng(Lat, Lon),
                zoom: 10,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);


            markercode = new google.maps.Marker({
                draggable:false,
                animation: google.maps.Animation.DROP,
                map:map,
                position: new google.maps.LatLng(Lat, Lon),
                title:"mattanchery - from code page!"
            });

            google.maps.event.addListener(markercode, 'click', toggleBounce);
        }

        function toggleBounce() {
            if (markercode.getAnimation() != null) {
                markercode.setAnimation(null);
            } else {
                markercode.setAnimation(google.maps.Animation.BOUNCE);
            }
        }

        function BtnLocateMe_onclick() {
            var myLatlng;
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(function (position) {
                    myLatlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);

                    if(markermyLatlngCount==0){
                        markermyLatlng = new google.maps.Marker({
                            draggable:true,
                            animation: google.maps.Animation.DROP,
                            map:map,
                            position: myLatlng,
                            title:"I am here!"
                        });
                        markermyLatlngCount=markermyLatlngCount+1;
                    }
                    else
                    {
                        map.setCenter(myLatlng);              
                    }
                },
                function () {
                    handleNoGeolocation(true);
                });
            } else {
                handleNoGeolocation(false);
            }
        }

        function handleNoGeolocation(errorFlag) {
            if (errorFlag) {
                var content = 'Error: The Geolocation service failed or blocked.';
            } else {
                var content = 'Error: Your browser doesn\'t support geolocation.';
            }
            alert(content);
         }

    </script>
    <style type="text/css">
        #map_canvas
        {
            height: 543px;
            width: 754px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <input id="BtnLocateMe" type="button" value="Locate Me" onclick="BtnLocateMe_onclick()" />
    <div id="map_canvas"></div>
    </div>
    </form>
</body>

CODE:


    public string dbLat = "9.964455";
    public string dbLon = "76.253099";
    protected void Page_Load(object sender, EventArgs e)
    {


    }

Wednesday, August 10, 2011

Nested Repeater in asp.net

No comments:


--Tables used.


CREATE TABLE [dbo].[user_types](
[ut_id] [int] IDENTITY(1,1) NOT NULL,
[ut_name] [varchar](50) NULL
)
------------------------
CREATE TABLE [dbo].[users](
[u_id] [int] IDENTITY(1,1) NOT NULL,
[u_ut_id] [int] NULL,
[u_name] [varchar](50) NULL,
[u_password] [varchar](50) NULL
)
-------------------------

Default.aspx

<body>
    <form id="form1" runat="server">
    <div>
    <%@ Import Namespace="System.Data" %>
        <h1 style="background-color:Lime;">Nested Repeater</h1>
        <asp:Repeater ID="Repeater1" runat="server">
            <ItemTemplate>
                <h2 style="background-color:Aqua;" >Children of <%# DataBinder.Eval(Container.DataItem, "ut_name")%></h2>
                <asp:Repeater ID="Repeater2" datasource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("typerelation") %>' runat="server">
                    <ItemTemplate>
                        <h3 style="background-color:Olive;">child item <%# DataBinder.Eval(Container.DataItem, "[\"u_name\"]")%></h3>
                    </ItemTemplate>
                </asp:Repeater>
            </ItemTemplate>
        </asp:Repeater>
    </div>
    </form>
</body>

-----------------------------

Default.aspx.cs

using System.Data;
using System.Data.SqlClient;


protected void Page_Load(object sender, EventArgs e)
    {
        DataSet DsRep = new DataSet();
        SqlCommand SqlCmd = new SqlCommand();
        DataTable DtRep;
        string con = @"Server=.\SQLEXPRESS; Database=tutorials; uid=sa; pwd=asdf123*;";
        string command = "";


        command = "select ut_id,ut_name from user_types";
        DtRep = new DataTable();
        new SqlDataAdapter(command, con).Fill(DsRep, "parent");
     
        command = "select u_id,u_ut_id,u_name from users";
        DtRep=new DataTable();
        new SqlDataAdapter(command, con).Fill(DsRep, "child");


        DsRep.Relations.Add("typerelation", DsRep.Tables["parent"].Columns["ut_id"], DsRep.Tables["child"].Columns["u_ut_id"]);


        Repeater1.DataSource = DsRep.Tables[0];
        Page.DataBind();
    }

Tuesday, December 21, 2010

asp.net and sql server

No comments:
aspx page

<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
   
    </div>
    <asp:DropDownList ID="DropDownList1" runat="server">
    </asp:DropDownList>
    <asp:Button ID="Button2" runat="server" onclick="Button2_Click"
        Text="Load all" />
    </form>
</body>

web.config

<appSettings>
        <add key="localhost" value="dbConnectionString"/>
    </appSettings>
    <connectionStrings>
        <add name="dbConnectionString" connectionString="Data Source=.\SQLEXPRESS; User ID=sa; Password=pswd; Database=testdatas; TimeOut=1 " providerName="System.Data.SqlClient"/>
    </connectionStrings>

aspx page.cs

public partial class _Default : System.Web.UI.Page
{
    SqlConnection sqlcon;
    SqlCommand SqlCmd;
    string ConnectionName = "";
    string ConnectionString = "";

    SqlDataReader SqlDr;
    List<string> LstString;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Response.Write(DateTime.Now.ToString());
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        ConnectionName = ConfigurationManager.AppSettings["localhost"].ToString();
        ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ToString();
        sqlcon = new SqlConnection();
        SqlCmd = new SqlCommand();
        sqlcon.ConnectionString = ConnectionString;
        SqlCmd.CommandText = "insert into tbone (name) values (@users)";
        SqlCmd.Parameters.AddWithValue("@users",TextBox1.Text);
        SqlCmd.Connection = sqlcon;
        sqlcon.Open();
        SqlCmd.ExecuteNonQuery();
        sqlcon.Close();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        ConnectionName = ConfigurationManager.AppSettings["localhost"].ToString();
        ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ToString();
        sqlcon = new SqlConnection();
        SqlCmd = new SqlCommand();
        LstString = new List<string>();
        sqlcon.ConnectionString = ConnectionString;
        SqlCmd.CommandText = "select * from tbone";
        SqlCmd.Parameters.AddWithValue("@users", TextBox1.Text);
        SqlCmd.Connection = sqlcon;
        sqlcon.Open();

        SqlDr = SqlCmd.ExecuteReader();
        while (SqlDr.Read())
        {
            LstString.Add(SqlDr["name"].ToString());
        }
        SqlDr.Close();
        sqlcon.Close();

        DropDownList1.DataSource = LstString;
        DropDownList1.DataBind();
    }
}

Wednesday, August 18, 2010

GridView for listing download link

No comments:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" EnableModelValidation="True">
        <Columns>
            <asp:HyperLinkField DataNavigateUrlFields="url_data_field" DataNavigateUrlFormatString="download_folder/{0}" 
            HeaderText="View" Text="Download" />
        </Columns>
    </asp:GridView>

Tuesday, June 22, 2010

connect silverlight with ms sql server

No comments:
1. File->New Silverlight Application  and name, say “silverlight_wcf_sql”
2. Check the checkbox to host the silverlight application in a new web application “silverlight_wcf_sql.Web”
3. Silverlight page design
xaml_design
4. Add a new WCF Service and name it sql_wcf.svc
5. Add a method say “GetName()” like

[OperationContract]
public string GetName()
{
//refer attached file
}

OperationContract attribute above the method name indicates that this method can be called from a WCF client.
  • Refer the sample project attached.
6. Right click the Silverlight Application “silverlight_wcf_sql” and add Service Reference. Add “sql_wcf.svc” as Service Reference and name it “Silverlight_wcf_service_reference”
7. Go to MainPage.xaml and double click the button to generate BtnClickMe_Click event and type the code

private void BtnClickMe_Click(object sender, RoutedEventArgs e)
{
BtnClickMe.IsEnabled = false;
Silverlight_wcf_service_reference.sql_wcfClient myclient = new Silverlight_wcf_service_reference.sql_wcfClient();
myclient.GetNameCompleted += new EventHandler(myclient_GetNameCompleted);
myclient.GetNameAsync();
txtBlkSQL.Text = "Receiving data...";
LbMessage.Content = "http://www.rodriguesjax.blogspot.com";
}


void myclient_GetNameCompleted(object sender, Silverlight_wcf_service_reference.GetNameCompletedEventArgs e)
{
txtBlkSQL.Text = (string)e.Result;
BtnClickMe.IsEnabled = true;
}


Click here to download silverlight_wcf_sql.rar
use visual studio 2010

Wednesday, June 9, 2010

Getting started silverlight

No comments:
  • Open Visual Studio and Click File->New Project… And Select Silverlight Application in Silverlight Templates. You can give a name to the project say MyFirstApplication and click OK.Add new project
  • This is to select whether you need to add a web application in the solution to host the silverlight file(xap). This is optional depending upon your requirement. This is similar to adding projects to a solution.
Host silverlight in a new project
        • Drag and drop a Button and TextBlock control from the ToolBox in MainPage.xaml. You may adjust the width of TextBlock. Then double click the button to go to the ‘button1_Click’ event in the code file(MainPage.xaml.cs).  You may be able to see other available events for the control in the Events tab in Properties window. Double click a event to go to the particular event.
Add the code in the MainPage.xaml.csType the code below in the button1_Click event assuming Button name is ‘button1’ and TextBox name is textBlock1
private void button1_Click(object sender, RoutedEventArgs e)
{
    textBlock1.Text = "Hello, Welcome to silverlight";
}
  • Press F5 to start debugging the silverlight application.
Press F5 to start debugging the application

Click here to download the sample file

Share it Facebook  Twitter

Tuesday, May 25, 2010

Free download Ajax Control Toolkit

No comments:
Visit http://www.asp.net/ajax to get the download link..
Extract the downloaded file
Create a new Toolbox tab then click choose items and and pick AjaxControlToolkit.dll in the extracted folder.
Then click ok.

Calendar for asp.net TextBox control using ASP.NET AJAX Calendar Extender

No comments:
CalendarExtender is a asp.net ajax extender that can be used with any textbox. This provides a client side date picker.

Downlaod toolkit from http://ajaxcontroltoolkit.codeplex.com/

code:
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy" TargetControlID="TextBox1">
        </asp:CalendarExtender>
    </div>
    </form>
</body>
  • In order to get a Calendar with an associated calendar icon image
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<body>
    <form id="form1" runat="server">
    <div>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Image ID="Image1" runat="server" ImageUrl="~/images/cal.png" />
        <asp:CalendarExtender ID="CalendarExtender1" runat="server" Format="dd/MM/yyyy" TargetControlID="TextBox1" PopupButtonID="Image1">
        </asp:CalendarExtender>
    </div>
    </form>
</body>

Friday, February 19, 2010

File Uploader using asp.net c#

No comments:
web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
<httpRuntime executionTimeout="90" maxRequestLength="200000" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="100"/>
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>


  • Default.aspx.cs File
static string fn1;
protected void BtnUpload_Click(object sender, EventArgs e)
{
try
{
if ((FileUploader.HasFile) && (FileUploader.PostedFile.ContentLength > 0) && FileUploader.PostedFile.ContentLength <= 20000000)
{
fn1 = System.IO.Path.GetFileName(FileUploader.PostedFile.FileName);
string SaveLocation = Server.MapPath("public_files") + "\\" + fn1;FileUploader.PostedFile.SaveAs(SaveLocation);
lbMessage.Text = "Upload successess... Have a nice day...<a href='http://www.twitter.com/rodriguesjax'>Go to Twitter </a><p>Files saved to " + SaveLocation + "</p>";
}
else
{
lbMessage.Text = "please select a file less than 20MB and greater than 0MB.";
}
}
catch (Exception ex)
{
lbMessage.Text = "Sorry. Upload Failed : " + ex.Message;
}
}

Monday, December 14, 2009

Tuesday, June 23, 2009

Tuesday, April 7, 2009

Device Control Through PC - My First Post...

No comments:
In this project we can control household electrical or industrial appliances using a computer where there is a parallel port interface between the switching circuit and computer.
Jerome Jackson Rodrigues.
--Thank you.