Pages

Showing posts with label vb. Show all posts
Showing posts with label vb. Show all posts

Friday, 12 September 2014

How to Get Data From Wikipedia Using API and jQuery in C#

How to Get Data From Wikipedia Using API and jQuery in C#
                                                                 
.Aspx File
 
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="WikirRference.aspx.vb" Inherits="Default2" %>

<!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 runat="server">
    <script src="https://googledrive.com/host/0Bw4NrxH2nTVqMnliTHpSY0U4ZE0" type="text/javascript"></script>

    <script src="https://googledrive.com/host/0Bw4NrxH2nTVqYndKU2p0Z2s3M1E" type="text/javascript"></script>

    <script src="https://googledrive.com/host/0Bw4NrxH2nTVqX3VZazJtMmxSNW8" type="text/javascript"></script>
    <title></title>
    <script type="text/javascript">
        $(document).ready(function () {
        });
        function searchdata() {

            var q = $("#searchterm").val();
            $.getJSON("http://en.wikipedia.org/w/api.php?callback=?",
              {
                  srsearch: q,
                  action: "query",
                  list: "search",
                  format: "json"

              },
              function (data) {
                  $("#results").empty();
                  $("#results").append("Results for <b>" + q + "</b> </br>");
                  $("#results").append("<div>&nbsp;</div>");
                  $.each(data.query.search, function (i, item) {
                      $("#results").append("<div><a href='http://en.wikipedia.org/wiki/" + encodeURIComponent(item.title) + "'>" + item.title + "</a> : " + item.snippet + "</div>");
                  });
              });


        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div style="border: 2px solid #a1a1a1; padding: 10px 40px; background: #dddddd; width: 300px; border-radius: 25px; height: 60px; text-align: left;">
            <b>Wikipedia API Search Using jQuery By http://fantasyaspnet.blogspot.in/</b><br />
            (This Wikipedia API will give the search results and references more than one.)
        </div>
        <div style="padding-left: 75px; padding-top: 15px;">
            <input id="searchterm" type="text" />
            <input id="search" type="button" value="Search" onclick="searchdata();" />
        </div>
        <div>&nbsp;</div>
        <div id="results" style="width: 300px; box-shadow: 10px 10px 5px #888888;">
        </div>
    </form>
</body>
</html>

Live Demo

Wikipedia API Search Using jQuery By http://fantasyaspnet.blogspot.in/
(This Wikipedia API will give the search results and references more than one.)
 




Wednesday, 26 February 2014

How to Create Captcha with Refresh Button in C#, VB.NET

How to Create Captcha with Refresh Button in C#, VB.NET 

.Aspx File
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Captcha Image with Refresh Button</title>
<script type="text/javascript">
    function RefreshCaptcha() {
        var img = document.getElementById("imgCaptcha");
        img.src = "Handler.ashx?query=" + Math.random();
    }
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<img src="Handler.ashx" id="imgCaptcha" />
<a href="#" onclick="javascript:RefreshCaptcha();">Refresh</a>
</div>
</form>
</body>
</html>

Now Right click on website
 -> Select Add New Item
 -> Select Generic Handler file and give name as Handler.ashx and click ok

open Handler.ashx
 
c#

 <%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Web;

public class Handler : IHttpHandler {

public void ProcessRequest (HttpContext context) {
using (Bitmap b = new Bitmap(150, 40, PixelFormat.Format32bppArgb))
{
using (Graphics g = Graphics.FromImage(b))
{
Rectangle rect = new Rectangle(0, 0, 149, 39);
g.FillRectangle(Brushes.White, rect);

// Create string to draw.
Random r = new Random();
int startIndex = r.Next(1, 5);
int length = r.Next(5, 10);
String drawString = Guid.NewGuid().ToString().Replace("-", "0").Substring(startIndex, length);

// Create font and brush.
Font drawFont = new Font("Arial", 16, FontStyle.Italic | FontStyle.Strikeout);
using (SolidBrush drawBrush = new SolidBrush(Color.Black))
{
// Create point for upper-left corner of drawing.
PointF drawPoint = new PointF(15, 10);

// Draw string to screen.
g.DrawRectangle(new Pen(Color.Red, 0), rect);
g.DrawString(drawString, drawFont, drawBrush, drawPoint);
}
b.Save(context.Response.OutputStream, ImageFormat.Jpeg);
context.Response.ContentType = "image/jpeg";
context.Response.End();
}
}
}
public bool IsReusable {
get {
return false;
}
}
}

VB


 <%@ WebHandler Language="VB" Class="Handler2" %>
Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Web

Public Class Handler2 : Implements IHttpHandler

Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Using b As New Bitmap(150, 40, PixelFormat.Format32bppArgb)
Using g As Graphics = Graphics.FromImage(b)
Dim rect As New Rectangle(0, 0, 149, 39)
g.FillRectangle(Brushes.White, rect)

' Create string to draw.
Dim r As New Random()
Dim startIndex As Integer = r.[Next](1, 5)
Dim length As Integer = r.[Next](5, 10)
Dim drawString As [String] = Guid.NewGuid().ToString().Replace("-", "0").Substring(startIndex, length)

' Create font and brush.
Dim drawFont As New Font("Arial", 16, FontStyle.Italic Or FontStyle.Strikeout)
Using drawBrush As New SolidBrush(Color.Black)
' Create point for upper-left corner of drawing.
Dim drawPoint As New PointF(15, 10)

' Draw string to screen.
g.DrawRectangle(New Pen(Color.Red, 0), rect)
g.DrawString(drawString, drawFont, drawBrush, drawPoint)
End Using
b.Save(context.Response.OutputStream, ImageFormat.Jpeg)
context.Response.ContentType = "image/jpeg"
context.Response.[End]()
End Using
End Using
End Sub

Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property

End Class

Demo




Thursday, 13 February 2014

What is The Difference between Throw and Throw ex in C# Asp.Net

What is The Difference between Throw and Throw ex in C# Asp.Net



try {
 // do some operation that can fail
 } catch (Exception ex)
 {
 // do some local cleanup
 throw;
 }




try {
 // do some operation that can fail
 } catch (Exception ex)
 {
 // do some local cleanup
 throw ex;
 }


How to Count Number of Online Users in Asp.Net Using C#, VB.NET

How to Count Number of Online Users in Asp.Net Using C#, VB.NET



<%@ Application Language="C#" %>
 <script runat="server">
 void Application_Start(object sender, EventArgs e)
 {
 // Code that runs on application startup Application["OnlineVisitors"] = 0;
 } '
void Application_End(object sender, EventArgs e)
 {
 // Code that runs on application shutdown } void Application_Error(object sender, EventArgs e)
 {
 // Code that runs when an unhandled error occurs
 }
 void Session_Start(object sender, EventArgs e)
 {
 // Code that runs when a new session is started Application.Lock();
 Application["OnlineVisitors"] = (int)Application["OnlineVisitors"] + 1;
 Application.UnLock();
 }
 void Session_End(object sender, EventArgs e)
 {
 // Code that runs when a session ends.
 // Note: The Session_End event is raised only when the sessionstate mode 
// is set to InProc in the Web.config file. If session mode is set to StateServer
 // or SQLServer, the event is not raised. Application.Lock();
 Application["OnlineVisitors"] = (int)Application["OnlineVisitors"] - 1;
 Application.UnLock();
 }
 </script>




<system.web>
 <sessionState mode="InProc" cookieless="false" timeout="20"/>
 </system.web>




<html xmlns="http://www.w3.org/1999/xhtml">
 <head id="Head1" runat="server">
 <title>Demo</title>
 </head>
 <body>
 <form id="form1" runat="server">
 <table>
 <tr>
 <td>
 <b>No of Users Online:</b>
 </td>
 <td style="color:Red">
 <%=Application["OnlineVisitors"].ToString()%>
 </td>
 </tr>
 </table>
 </form>
 </body>
 </html>


Demo:





Download:


Thursday, 4 July 2013

How To Remove Last Character from String in VB.NET C# Asp.Net

 How To Remove Last Character from String in VB.NET C#  Asp.Net

Method 1 in C#

protected void Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.Remove(istr.Length - 1, 1);
Response.Write(ostr);
}

Method 1 in VB.NET

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim istr As String = "1,2,3,4,5,6,7,8,9,10,"
Dim ostr As String = istr.Remove(istr.Length - 1, 1)
Response.Write(ostr)
End Sub

Method 2 in C#

protected void Page_Load(object sender, EventArgs e)
{
string istr = "1,2,3,4,5,6,7,8,9,10,";
string ostr = istr.Trim(",".ToCharArray());
Response.Write(ostr);
}

Method 2 in VB.NET

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim istr As String = "1,2,3,4,5,6,7,8,9,10,"
Dim ostr As String = istr.Trim(",".ToCharArray())
Response.Write(ostr)
End Sub

Wednesday, 3 July 2013

How To Break or Exit For Each Loop in VB.NET Or Exit/Break For Loop in C#, VB.NET Asp.Net

How To Break or Exit For Each Loop in VB.NET Or Exit/Break For Loop in C#, VB.NET Asp.Net

C# Code: for loop example

for (int i = 0; i < 10; i++)
{
int j = 4;
if (j == i)
{
break;
}
}

for each loop example

string listingId = string.Empty;
foreach (GridViewRow gvRow in grdSearchResults.Rows)
{
if (gvRow.Cells[2].Text != "0")
{
listingId = gvRow.Cells[2].Text;
}
if (!string.IsNullOrEmpty(listingId))
{
break;
}
}

VB Code: for loop example

For i As Integer = 0 To 9
Dim j As Integer = 4
If j = i Then
Exit For
End If
Next

for each loop example

Dim listingId As String = String.Empty
For Each gvRow As GridViewRow In grdSearchResults.Rows
If gvRow.Cells(2).Text <> "0" Then
listingId = gvRow.Cells(2).Text
End If
If Not String.IsNullOrEmpty(listingId) Then
Exit For
End If
Next

Thursday, 23 May 2013

How To Display Rows as Columns in Grid view in Asp.net using C# And VB.NET

How To Display Rows as Columns in Grid view in Asp.net using C# And VB.NET


Program:

.Aspx File

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="rawascolum.aspx.cs" Inherits="rawascolum" %>

<!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 runat="server">
    <title>Raw As Columns</title>
    <style type="text/css">
body
{
font-family:Calibri;
}
.gridcss
{
background:#B52025;
font-weight:bold;
color:White;
}
</style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
<tr>
<td><b>Normal Gridview</b></td>
<td>&nbsp;&nbsp;</td>
<td><b>Converted Gridview</b></td>
</tr>
<tr>
<td>
<asp:GridView ID="gvnormal" runat="server">
<HeaderStyle BackColor="#B52025" Font-Bold="true" ForeColor="White" />
</asp:GridView>
</td>
<td>&nbsp;&nbsp;</td>
<td>
<asp:GridView ID="gvconverted" runat="server" OnRowDataBound=gvconverted_RowDataBound>
</asp:GridView>
</td>
</tr>
</table>
    </div>
    </form>
</body>
</html>

.CS File

using System;
using System.Data;
using System.Data.SqlClient;
using System.Web.UI.WebControls;

public partial class rawascolum : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridviewData();
        }
    }
    protected void BindGridviewData()
    {
        DataTable dt = new DataTable();
        dt.Columns.Add("UserId", typeof(Int32));
        dt.Columns.Add("UserName", typeof(string));
        dt.Columns.Add("Education", typeof(string));
        dt.Columns.Add("Location", typeof(string));
        DataRow dtrow = dt.NewRow();  
        dtrow["UserId"] = 1;          
        dtrow["UserName"] = "SureshDasari";
        dtrow["Education"] = "B.Tech";
        dtrow["Location"] = "Chennai";
        dt.Rows.Add(dtrow);
        dtrow = dt.NewRow();            
        dtrow["UserId"] = 2;            
        dtrow["UserName"] = "MadhavSai";
        dtrow["Education"] = "MBA";
        dtrow["Location"] = "Nagpur";
        dt.Rows.Add(dtrow);
        dtrow = dt.NewRow();          
        dtrow["UserId"] = 3;          
        dtrow["UserName"] = "MaheshDasari";
        dtrow["Education"] = "B.Tech";
        dtrow["Location"] = "Nuzividu";
        dt.Rows.Add(dtrow);
        gvnormal.DataSource = dt;
        gvnormal.DataBind();
        gvconverted.DataSource = ConvertColumnsAsRows(dt);
        gvconverted.DataBind();
        gvconverted.HeaderRow.Visible = false;
    }
    protected void gvconverted_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Cells[0].CssClass = "gridcss";
        }
    }
 
    public DataTable ConvertColumnsAsRows(DataTable dt)
    {
        DataTable dtnew = new DataTable();
     
        for (int i = 0; i <= dt.Rows.Count; i++)
        {
            dtnew.Columns.Add(Convert.ToString(i));
        }
        DataRow dr;
     
        for (int j = 0; j < dt.Columns.Count; j++)
        {
            dr = dtnew.NewRow();
            dr[0] = dt.Columns[j].ToString();
            for (int k = 1; k <= dt.Rows.Count; k++)
                dr[k] = dt.Rows[k - 1][j];
            dtnew.Rows.Add(dr);
        }
        return dtnew;
    }
}

VB File

aImports System.Data
Imports System.Web.UI.WebControls

Partial Class Default2
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGridviewData()
End If
End Sub
Protected Sub BindGridviewData()
Dim dt As New DataTable()
dt.Columns.Add("UserId", GetType(Int32))
dt.Columns.Add("UserName", GetType(String))
dt.Columns.Add("Education", GetType(String))
dt.Columns.Add("Location", GetType(String))
Dim dtrow As DataRow = dt.NewRow()
' Create New Row
dtrow("UserId") = 1
'Bind Data to Columns
dtrow("UserName") = "SureshDasari"
dtrow("Education") = "B.Tech"
dtrow("Location") = "Chennai"
dt.Rows.Add(dtrow)
dtrow = dt.NewRow()
' Create New Row
dtrow("UserId") = 2
'Bind Data to Columns
dtrow("UserName") = "MadhavSai"
dtrow("Education") = "MBA"
dtrow("Location") = "Nagpur"
dt.Rows.Add(dtrow)
dtrow = dt.NewRow()
' Create New Row
dtrow("UserId") = 3
'Bind Data to Columns
dtrow("UserName") = "MaheshDasari"
dtrow("Education") = "B.Tech"
dtrow("Location") = "Nuzividu"
dt.Rows.Add(dtrow)
gvnormal.DataSource = dt
gvnormal.DataBind()
gvconverted.DataSource = ConvertColumnsAsRows(dt)
gvconverted.DataBind()
gvconverted.HeaderRow.Visible = False
End Sub
Protected Sub gvconverted_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(0).CssClass = "gridcss"
End If
End Sub
Public Function ConvertColumnsAsRows(ByVal dt As DataTable) As DataTable
Dim dtnew As New DataTable()
For i As Integer = 0 To dt.Rows.Count
dtnew.Columns.Add(Convert.ToString(i))
Next
Dim dr As DataRow

For j As Integer = 0 To dt.Columns.Count - 1
dr = dtnew.NewRow()
dr(0) = dt.Columns(j).ToString()
For k As Integer = 1 To dt.Rows.Count
dr(k) = dt.Rows(k - 1)(j)
Next
dtnew.Rows.Add(dr)
Next
Return dtnew
End Function
End Class

Demo:

How To Display Rows as Columns in Grid view in Asp.net using C# And VB.NET
How To Display Rows as Columns in Grid view in Asp.net using C# And VB.NET

Download Demo

Wednesday, 22 May 2013

How To Get Number of Facebook Likes for a Url or Website jQuery in C# and VB

 How To Get Number of Facebook Likes for a URL or Website jQuery in C# and VB


Program:

.Aspx File

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>facebook</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#btnurl').click(function () {
            var url = $('#txturl').val();
            document.getElementById('tbDetails').style.display = 'block';
            $.ajax({
                type: "POST",
                url: "WebService.asmx/BindDatatable",
                data: "{urltxt:'" + url + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    for (var i = 0; i < data.d.length; i++) {
                        $("#tbDetails").append("<tr><td>" + data.d[i].Url + "</td><td>" + data.d[i].SharedCount + "</td><td>" + data.d[i].LikeCount + "</td><td>" + data.d[i].CommentCount + "</td><td>" + data.d[i].ClickCount + "</td><td>" + data.d[i].TotalCount + "</td></tr>");
                    }
                },
                error: function (result) {
                    alert("Error");
                }
            });
        });
    });
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><b>Enter Url:</b></td>
<td><input type="text" id="txturl" /> </td>
</tr>
<tr>
<td></td>
<td><input type="button" id="btnurl" value="Get Url Count" /> </td>
</tr>
</table>
</div>
<div>
<table id="tbDetails" cellpadding="1" cellspacing="1" style="border:solid 1px #000000; display:none">
<thead style="background-color:#DC5807; color:White; font-weight:bold">
<tr>
<td>URL</td>
<td>Shared Count</td>
<td>Likes Count</td>
<td>Comments Count</td>
<td>Clicks Count</td>
<td>Total Count</td>
</tr>
</thead>
</table>
</div>
</form>
</body>
</html>

Aspx.cs

using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Net;
using System.Web.Services;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
    [WebMethod]
    public UrlDetails[] BindDatatable(string urltxt)
    {
        List<UrlDetails> details = new List<UrlDetails>();
        WebClient web = new WebClient();
        string url = string.Format("https://api.facebook.com/method/fql.query?query=SELECT url, share_count, like_count, comment_count, total_count, click_count FROM link_stat where url='" + urltxt + "'");
        string response = web.DownloadString(url);
        DataSet ds = new DataSet();
        using (StringReader stringReader = new StringReader(response))
        {
            ds = new DataSet();
            ds.ReadXml(stringReader);
        }
        DataTable dt = ds.Tables["link_stat"];
        foreach (DataRow dtrow in dt.Rows)
        {
            UrlDetails website = new UrlDetails();
            website.Url = dtrow["url"].ToString();
            website.LikeCount = dtrow["like_count"].ToString();
            website.SharedCount = dtrow["share_count"].ToString();
            website.CommentCount = dtrow["comment_count"].ToString();
            website.ClickCount = dtrow["click_count"].ToString();
            website.TotalCount = dtrow["total_count"].ToString();
            details.Add(website);
        }
        return details.ToArray();
    }
    public class UrlDetails
    {
        public string Url { get; set; }
        public string SharedCount { get; set; }
        public string LikeCount { get; set; }
        public string CommentCount { get; set; }
        public string ClickCount { get; set; }
        public string TotalCount { get; set; }
    }
}

VB

Imports System.Collections.Generic
Imports System.Data
Imports System.IO
Imports System.Net
Imports System.Web.Services

''' <summary>
''' Summary description for AutoCompleteService
''' </summary>
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<WebService([Namespace]:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class WebService2
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function BindDatatable(ByVal urltxt As String) As UrlDetails()
Dim details As New List(Of UrlDetails)()
Dim web As New WebClient()
Dim url As String = String.Format("https://api.facebook.com/method/fql.query?query=SELECT url, share_count, like_count, comment_count, total_count, click_count FROM link_stat where url='" & urltxt & "'")
Dim response As String = web.DownloadString(url)
Dim ds As New DataSet()
Using stringReader As New StringReader(response)
ds = New DataSet()
ds.ReadXml(stringReader)
End Using
Dim dt As DataTable = ds.Tables("link_stat")
For Each dtrow As DataRow In dt.Rows
Dim website As New UrlDetails()
website.Url = dtrow("url").ToString()
website.LikeCount = dtrow("like_count").ToString()
website.SharedCount = dtrow("share_count").ToString()
website.CommentCount = dtrow("comment_count").ToString()
website.ClickCount = dtrow("click_count").ToString()
website.TotalCount = dtrow("total_count").ToString()
details.Add(website)
Next
Return details.ToArray()
End Function
Public Class UrlDetails
Public Property Url() As String
Get
Return m_Url
End Get
Set(ByVal value As String)
m_Url = value
End Set
End Property
Private m_Url As String
Public Property SharedCount() As String
Get
Return m_SharedCount
End Get
Set(ByVal value As String)
m_SharedCount = value
End Set
End Property
Private m_SharedCount As String
Public Property LikeCount() As String
Get
Return m_LikeCount
End Get
Set(ByVal value As String)
m_LikeCount = value
End Set
End Property
Private m_LikeCount As String
Public Property CommentCount() As String
Get
Return m_CommentCount
End Get
Set(ByVal value As String)
m_CommentCount = value
End Set
End Property
Private m_CommentCount As String
Public Property ClickCount() As String
Get
Return m_ClickCount
End Get
Set(ByVal value As String)
m_ClickCount = value
End Set
End Property
Private m_ClickCount As String
Public Property TotalCount() As String
Get
Return m_TotalCount
End Get
Set(ByVal value As String)
m_TotalCount = value
End Set
End Property
Private m_TotalCount As String
End Class

End Class

Demo
 How TO Get Number of Facebook likes, Shares, Comments Count for URL or Website using jQuery in C# Asp.Net
 How TO Get Number of Facebook likes, Shares, Comments Count for URL or Website using jQuery in C# Asp.Net


How TO Get Number of Facebook likes, Shares, Comments Count for URL or Website using jQuery in C# and VB Asp.Net

 How TO Get Number of Facebook likes, Shares, Comments Count for URL or Website using jQuery in C# C# and VB Asp.Net


Program:

.Aspx File

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get facebook shares, comments, likes count of urls</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $('#btnurl').click(function () {
            var url = $('#txturl').val();
            document.getElementById('tbDetails').style.display = 'block';
            $.ajax({
                type: "POST",
                url: "WebService.asmx/BindDatatable",
                data: "{urltxt:'" + url + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                    for (var i = 0; i < data.d.length; i++) {
                        $("#tbDetails").append("<tr><td>" + data.d[i].Url + "</td><td>" + data.d[i].SharedCount + "</td><td>" + data.d[i].LikeCount + "</td><td>" + data.d[i].CommentCount + "</td><td>" + data.d[i].ClickCount + "</td><td>" + data.d[i].TotalCount + "</td></tr>");
                    }
                },
                error: function (result) {
                    alert("Error");
                }
            });
        });
    });
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td><b>Enter Url:</b></td>
<td><input type="text" id="txturl" /> </td>
</tr>
<tr>
<td></td>
<td><input type="button" id="btnurl" value="Get Url Count" /> </td>
</tr>
</table>
</div>
<div>
<table id="tbDetails" cellpadding="1" cellspacing="1" style="border:solid 1px #000000; display:none">
<thead style="background-color:#DC5807; color:White; font-weight:bold">
<tr>
<td>URL</td>
<td>Shared Count</td>
<td>Likes Count</td>
<td>Comments Count</td>
<td>Clicks Count</td>
<td>Total Count</td>
</tr>
</thead>
</table>
</div>
</form>
</body>
</html>

Aspx.cs

using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Net;
using System.Web.Services;


[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
    [WebMethod]
    public UrlDetails[] BindDatatable(string urltxt)
    {
        List<UrlDetails> details = new List<UrlDetails>();
        WebClient web = new WebClient();
        string url = string.Format("https://api.facebook.com/method/fql.query?query=SELECT url, share_count, like_count, comment_count, total_count, click_count FROM link_stat where url='" + urltxt + "'");
        string response = web.DownloadString(url);
        DataSet ds = new DataSet();
        using (StringReader stringReader = new StringReader(response))
        {
            ds = new DataSet();
            ds.ReadXml(stringReader);
        }
        DataTable dt = ds.Tables["link_stat"];
        foreach (DataRow dtrow in dt.Rows)
        {
            UrlDetails website = new UrlDetails();
            website.Url = dtrow["url"].ToString();
            website.LikeCount = dtrow["like_count"].ToString();
            website.SharedCount = dtrow["share_count"].ToString();
            website.CommentCount = dtrow["comment_count"].ToString();
            website.ClickCount = dtrow["click_count"].ToString();
            website.TotalCount = dtrow["total_count"].ToString();
            details.Add(website);
        }
        return details.ToArray();
    }
    public class UrlDetails
    {
        public string Url { get; set; }
        public string SharedCount { get; set; }
        public string LikeCount { get; set; }
        public string CommentCount { get; set; }
        public string ClickCount { get; set; }
        public string TotalCount { get; set; }
    }
}

VB

Imports System.Collections.Generic
Imports System.Data
Imports System.IO
Imports System.Net
Imports System.Web.Services

''' <summary>
''' Summary description for AutoCompleteService
''' </summary>
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
<WebService([Namespace]:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class WebService2
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function BindDatatable(ByVal urltxt As String) As UrlDetails()
Dim details As New List(Of UrlDetails)()
Dim web As New WebClient()
Dim url As String = String.Format("https://api.facebook.com/method/fql.query?query=SELECT url, share_count, like_count, comment_count, total_count, click_count FROM link_stat where url='" & urltxt & "'")
Dim response As String = web.DownloadString(url)
Dim ds As New DataSet()
Using stringReader As New StringReader(response)
ds = New DataSet()
ds.ReadXml(stringReader)
End Using
Dim dt As DataTable = ds.Tables("link_stat")
For Each dtrow As DataRow In dt.Rows
Dim website As New UrlDetails()
website.Url = dtrow("url").ToString()
website.LikeCount = dtrow("like_count").ToString()
website.SharedCount = dtrow("share_count").ToString()
website.CommentCount = dtrow("comment_count").ToString()
website.ClickCount = dtrow("click_count").ToString()
website.TotalCount = dtrow("total_count").ToString()
details.Add(website)
Next
Return details.ToArray()
End Function
Public Class UrlDetails
Public Property Url() As String
Get
Return m_Url
End Get
Set(ByVal value As String)
m_Url = value
End Set
End Property
Private m_Url As String
Public Property SharedCount() As String
Get
Return m_SharedCount
End Get
Set(ByVal value As String)
m_SharedCount = value
End Set
End Property
Private m_SharedCount As String
Public Property LikeCount() As String
Get
Return m_LikeCount
End Get
Set(ByVal value As String)
m_LikeCount = value
End Set
End Property
Private m_LikeCount As String
Public Property CommentCount() As String
Get
Return m_CommentCount
End Get
Set(ByVal value As String)
m_CommentCount = value
End Set
End Property
Private m_CommentCount As String
Public Property ClickCount() As String
Get
Return m_ClickCount
End Get
Set(ByVal value As String)
m_ClickCount = value
End Set
End Property
Private m_ClickCount As String
Public Property TotalCount() As String
Get
Return m_TotalCount
End Get
Set(ByVal value As String)
m_TotalCount = value
End Set
End Property
Private m_TotalCount As String
End Class

End Class

Demo


 How TO Get Number of Facebook likes, Shares, Comments Count for URL or Website using jQuery in C# Asp.Net
 How TO Get Number of Facebook likes, Shares, Comments Count for URL or Website using jQuery in C# Asp.Net


How To Delete Particular Row from Datatable Or Delete Selected Row From DataTable in C# and VB Asp.net

How To Delete Particular Row from Datatable Or Delete Selected Row From DataTable in C#  and VB Asp.net


Program:

.Aspx File C#

DataTable dt1 = new DataTable();
dt1 = ds.Tables[0];
for (int i = 0; i < dt.Columns.Count;i++ )
{
if (i == 3)
{
dt.Rows[i - 1].Delete();
dt.AcceptChanges();
}
}

VB

Dim dt1 As New DataTable()
dt1 = ds.Tables(0)
For i As Integer = 0 To dt.Columns.Count - 1
If i = 3 Then
dt.Rows(i - 1).Delete()
dt.AcceptChanges()
End If
Next

Wednesday, 24 April 2013

How to Ajax ModalPopUpExtender Example to edit the gridview row values in c# and VB asp.net

How to Ajax ModalPopUpExtender Example to edit the gridview row values in c# and VB asp.net 

Program:

.Aspx File

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!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 runat="server">
<title>Untitled Page</title>
<style type="text/css">
.modalBackground
{
background-color: Gray;
z-index: 10000;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:GridView runat="server" ID="gvdetails" DataKeyNames="ID" AutoGenerateColumns="false">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:ImageButton ID="imgbtn" ImageUrl="~/Edit.jpg" runat="server" Width="25" Height="25" onclick="imgbtn_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Designation" HeaderText="Designation" />
</Columns>
</asp:GridView>
<asp:Label ID="lblresult" runat="server"/>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="269px" Width="400px" style="display:none">
<table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#D55500">
<td colspan="2" style=" height:10%; color:White; font-weight:bold; font-size:larger" align="center">User Details</td>
</tr>
<tr>
<td align="right" style=" width:45%">
ID:
</td>
<td>
<asp:Label ID="lblID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="right">
Name:
</td>
<td>
<asp:Label ID="lblusername" runat="server"></asp:Label>
</td>
</tr>
<tr>
<tr>
<td align="right">
Designation:
</td>
<td>
<asp:TextBox ID="txtDesg" runat="server"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" onclick="btnUpdate_Click"/>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>

.Aspx.cs

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using AjaxControlToolkit;

// Made By Sizar Surani

public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindGridData();
}
}
protected void BindGridData()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Table_1", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
gvdetails.DataSource = dt;
gvdetails.DataBind();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("update Table_1 set Name=@Name,Designation=@Designation where ID=@ID", con);
cmd.Parameters.AddWithValue("@Name", lblusername.Text);
cmd.Parameters.AddWithValue("@Designation", txtDesg.Text);
cmd.Parameters.AddWithValue("@ID", Convert.ToInt32(lblID.Text));
cmd.ExecuteNonQuery();
con.Close();
lblresult.Text = lblusername.Text + " Details Updated Successfully";
lblresult.ForeColor = Color.Green;
BindGridData();
}
protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
ImageButton btndetails = sender as ImageButton;
GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
lblID.Text = gvdetails.DataKeys[gvrow.RowIndex].Value.ToString();
lblusername.Text = gvrow.Cells[1].Text;
txtDesg.Text = gvrow.Cells[2].Text;
this.ModalPopupExtender1.Show();
}
}

Demo:


How to Ajax ModalPopUpExtender Example to edit the gridview row values in c# and VB asp.net
How to Ajax ModalPopUpExtender Example to edit the gridview row values in c# and VB asp.net 


How to Put confirmation box with yes/no button options using modal popup in c# and VB Asp.net

How to Put  confirmation box with yes/no button options using modal popup in c# Asp.net

Program:

.Aspx File

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajax" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Untitled Page</title>
<style type="text/css">
.modalBackground
{
background-color: Gray;
z-index: 10000;
}

.GridviewDiv {font-size: 100%; font-family: 'Lucida Grande', 'Lucida Sans Unicode', Verdana, Arial, Helevetica, sans-serif; color: #303933;}
Table.Gridview{border:solid 1px #df5015;}
.Gridview th{color:#FFFFFF;border-right-color:#abb079;border-bottom-color:#abb079;padding:0.5em 0.5em 0.5em 0.5em;text-align:center}
.Gridview td{border-bottom-color:#f0f2da;border-right-color:#f0f2da;padding:0.5em 0.5em 0.5em 0.5em;}
.Gridview tr{color: Black; background-color: White; text-align:left}
:link,:visited { color: #DF4F13; text-decoration:none }

</style>
<script language="javascript" type="text/javascript">
    function closepopup() {
        $find('ModalPopupExtender1').hide();
    }
</script>
</head>
<body>
<form id="form1" runat="server">
<ajax:ToolkitScriptManager ID="ScriptManager1" runat="server">
</ajax:ToolkitScriptManager>
<asp:UpdatePanel ID="updatepnl1" runat="server">
<ContentTemplate>
<asp:GridView runat="server" ID="gvDetails" CssClass="Gridview"
DataKeyNames="ID" AutoGenerateColumns="false">
<HeaderStyle BackColor="#df5015" />
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:BoundField DataField="Designation" HeaderText="Designation" />
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="btnDelete" ImageUrl="~/Images/Delete.png" runat="server" onclick="btnDelete_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="lblresult" runat="server"/>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<ajax:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnNo" BackgroundCssClass="modalBackground">
</ajax:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="100px" Width="400px" style="display:none">
<table width="100%" style="border:Solid 2px #D46900; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-image:url(Images/header.gif)">
<td style=" height:10%; color:White; font-weight:bold;padding:3px; font-size:larger; font-family:Calibri" align="Left">Confirm Box</td>
<td style=" color:White; font-weight:bold;padding:3px; font-size:larger" align="Right">
<a href = "javascript:void(0)" onclick = "closepopup()"><img src="Images/Close.gif" style="border :0px" align="right"/></a>
  </td>
</tr>
<tr>
<td colspan="2" align="left" style="padding:5px; font-family:Calibri">
<asp:Label ID="lblUser" runat="server"/>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
<tr>
<td>
</td>
<td align="right" style="padding-right:15px">
<asp:ImageButton ID="btnYes" OnClick="btnYes_Click" runat="server" ImageUrl="~/Images/btnyes.jpg"/>
<asp:ImageButton ID="btnNo" runat="server" ImageUrl="~/Images/btnNo.jpg" />
</td>
</tr>
</table>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>

.Aspx.cs

using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("Data Source=SURANI-PC\\SA;Initial Catalog=demo;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindUserDetails();
        }
    }
    protected void BindUserDetails()
    {
        //connection open
        con.Open();
        //sql command to execute query from database
        SqlCommand cmd = new SqlCommand("Select * from Table_1", con);
        cmd.ExecuteNonQuery();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        //Binding data to gridview
        gvDetails.DataSource = ds;
        gvDetails.DataBind();
        con.Close();
    }
  protected void btnYes_Click(object sender, ImageClickEventArgs e)
  {
      //getting ID of particular row
      int ID = Convert.ToInt32(Session["ID"]);
      con.Open();
      SqlCommand cmd = new SqlCommand("delete from Table_1 where ID=" + ID, con);
      int result = cmd.ExecuteNonQuery();
      con.Close();
      if (result == 1)
      {
      lblresult.Text = Session["Name"] + " Details deleted successfully";
      lblresult.ForeColor = Color.Green;
      BindUserDetails();
      }
  }
  protected void btnDelete_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btndetails = sender as ImageButton;
        GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
        Session["ID"] = gvDetails.DataKeys[gvrow.RowIndex].Value.ToString();
        Session["Name"] = gvrow.Cells[0].Text;
        lblUser.Text = "Are you sure you want to delete " + Session["Name"] + " Details?";
        ModalPopupExtender1.Show();
    }
}

VB Code:

Imports System.Data
Imports System.Data.SqlClient
Imports System.Drawing
Imports System.Web.UI
Imports System.Web.UI.WebControls

Partial Class VBCode
    Inherits System.Web.UI.Page
    Private con As New SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB")
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        If Not IsPostBack Then
            BindUserDetails()
        End If
    End Sub
    Protected Sub BindUserDetails()
        'connection open
        con.Open()
        'sql command to execute query from database
        Dim cmd As New SqlCommand("Select * from UserDetails", con)
        cmd.ExecuteNonQuery()
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As New DataSet()
        da.Fill(ds)
        'Binding data to gridview
        gvDetails.DataSource = ds
        gvDetails.DataBind()
        con.Close()
    End Sub
    Protected Sub btnYes_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        'getting userid of particular row
        Dim userid As Integer = Convert.ToInt32(Session("UserId"))
        con.Open()
        Dim cmd As New SqlCommand("delete from UserDetails where UserId=" & userid, con)
        Dim result As Integer = cmd.ExecuteNonQuery()
        con.Close()
        If result = 1 Then
            lblresult.Text = Convert.ToString(Session("UserName")) & " Details deleted successfully"
            lblresult.ForeColor = Color.Green
            BindUserDetails()
        End If
    End Sub
    Protected Sub btnDelete_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        Dim btndetails As ImageButton = TryCast(sender, ImageButton)
        Dim gvrow As GridViewRow = DirectCast(btndetails.NamingContainer, GridViewRow)
        Session("UserId") = gvDetails.DataKeys(gvrow.RowIndex).Value.ToString()
        Session("UserName") = gvrow.Cells(0).Text
        lblUser.Text = "Are you sure you want to delete " & Convert.ToString(Session("UserName")) & " Details?"
        ModalPopupExtender1.Show()
    End Sub
End Class

Demo:


How to Put  confirmation box with yes/no button options using modal popup in c# and VB Asp.net
How to Put  confirmation box with yes/no button options using modal popup in c# and VB Asp.net

Tuesday, 23 April 2013

Create an application in vb which insert, delete and update data in the database

Create an application in vb which insert, delete and update data in the database.

Program:

Design:


Create an application in vb which insert, delete and update data in the database
Create an application in vb which insert, delete and update data in the database

Code:


Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim str As String

    Private Sub btninsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btninsert.Click
        conn = New SqlConnection("Data Source=SHIMEKA-PC;Initial Catalog=sizar;Persist Security Info=True;User ID=sa;Password=123")
        conn.Open()
        If rbtnmale.Checked Then

            Str = rbtnmale.Text



        Else

            str = rbtnfemale.Text



        End If
        cmd = New SqlCommand("Insert into stu(id,name,surname,number,gender,city) values('" & txtid.Text & "','" & txtname.Text & "','" & txtsurname.Text & "','" & txtnumber.Text & "','" & str & "','" & cbcity.SelectedItem & "')", conn)
        cmd.ExecuteNonQuery()
        conn.Close()
        reset()
        MessageBox.Show("value inserted successfully")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        conn = New SqlConnection("Data Source=SHIMEKA-PC;Initial Catalog=sizar;Persist Security Info=True;User ID=sa;Password=123")
        conn.Open()
        cmd = New SqlCommand("DELETE from stu where id='" & txtid.Text & "'", conn)
        cmd.ExecuteNonQuery()
        conn.Close()
        reset()
        MessageBox.Show(" row deleted successfully")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        conn = New SqlConnection("Data Source=SHIMEKA-PC;Initial Catalog=sizar;Persist Security Info=True;User ID=sa;Password=123")
        conn.Open()
        If rbtnmale.Checked Then

            str = rbtnmale.Text



        Else

            str = rbtnfemale.Text



        End If
        cmd = New SqlCommand("update stu set surname='" & txtsurname.Text & "',number='" & txtnumber.Text & "',name='" & txtname.Text & "',gender='" & str & "',city='" & cbcity.SelectedItem & "' where id='" & txtid.Text & "'", conn)
        cmd.ExecuteNonQuery()
        conn.Close()
        reset()
        MessageBox.Show(" row updated successfully")
    End Sub
    Public Sub reset()
        txtid.Text = ""
        txtname.Text = ""
        txtnumber.Text = ""
        txtsurname.Text = ""
    End Sub

   

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

    End Sub
End Class



Saturday, 3 November 2012

Create a Position application in VB that changes the position of text in a label according to the command selected by the user. The application should include a Program menuwith an Exit command and a Position menu with TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, and BottomRight commands

Create a Position application in VB that changes the position of text in a label according to the command selected by the user. The application should include a Program menuwith an Exit command and a Position menu with TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, and BottomRight commands

Description:
In this post we are going to learn the use of dialog control. Include all the five dialog controls like OpenFileDialog,SaveFileDialog,FolderBrowserDialog,FontDialog,ColorDialog.

Open Microsoft visual studio
File-> New -> Project -> visual vb -> Windows Forms Application.

Program:

Design a window form as shown in figure in vb


Create a Position application in VB that changes the position of text in a label according to the command selected by the user. The application should include a Program menuwith an Exit command and a Position menu with TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, and BottomRight commands
Create a Position application in VB that changes the position of text in a label according to the command selected by the user. The application should include a Program menuwith an Exit command and a Position menu with TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, and BottomRight commands



Public Class Form1
    Private Sub TopCenterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TopCenterToolStripMenuItem.Click
        Label1.Location = New Point(0, 20)
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub TopCenterToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TopCenterToolStripMenuItem1.Click
        Label1.Location = New Point(125, 20)
    End Sub

    Private Sub TopRightToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TopRightToolStripMenuItem.Click
        Label1.Location = New Point(250, 20)
    End Sub

    Private Sub MiddleLeftToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MiddleLeftToolStripMenuItem.Click
        Label1.Location = New Point(0, 125)
    End Sub

    Private Sub MiddlCenterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MiddlCenterToolStripMenuItem.Click
        Label1.Location = New Point(125, 125)
    End Sub

    Private Sub MiddleRightToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MiddleRightToolStripMenuItem.Click
        Label1.Location = New Point(250, 125)
    End Sub

    Private Sub BottomTopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BottomTopToolStripMenuItem.Click
        Label1.Location = New Point(0, 250)
    End Sub

    Private Sub BottomCenterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BottomCenterToolStripMenuItem.Click
        Label1.Location = New Point(125, 250)
    End Sub

    Private Sub BottomRightToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BottomRightToolStripMenuItem.Click
        Label1.Location = New Point(250, 250)
    End Sub
End Class

Demo:

Create a Position application in VB that changes the position of text in a label according to the command selected by the user. The application should include a Program menuwith an Exit command and a Position menu with TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, and BottomRight commands