Thursday, 16 November 2017
Wednesday, 4 October 2017
Method for Create Dynamic Alpha Numeric Password in C#
Method for Create Dynamic Alpha Numeric Password in C#
This Method returns a dynamic String:-
public static string CreateDynamicPassword()
{
string _allowedChars = "0123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ";
Random randNum = new Random();
char[] chars = new char[8];
int allowedCharCount = _allowedChars.Length;
for (int i = 0; i < 8; i++)
{
chars[i] = _allowedChars[(int)((_allowedChars.Length) * randNum.NextDouble())];
}
return new string(chars);
}
Friday, 8 September 2017
Method for Grid Update in ASP.Net with C#
Method for Grid Update in ASP.Net with C#
ASPX page
<asp:GridView ID="grd" runat="server" CellPadding="4" AutoGenerateColumns="False" OnRowCancelingEdit="grd_RowCancelingEdit" OnRowEditing="grd_RowEditing" OnRowUpdating="grd_RowUpdating" AllowPaging="true" PageSize="15" OnPageIndexChanging="grd_PageIndexChanging" CssClass="ui-data-grid" OnSelectedIndexChanged="grd_SelectedIndexChanged" Width="707px">
<AlternatingRowStyle CssClass="gridAltrows" />
<SelectedRowStyle CssClass="gridSelected" />
<Columns>
<asp:TemplateField HeaderText="S.No." HeaderStyle-CssClass="col-center" ItemStyle-CssClass="col-center">
<ItemTemplate>
<asp:Label ID="lblrowno" runat="server" Text='<%# Container.DataItemIndex + 1 %>'></asp:Label>
<asp:HiddenField ID="hdnkey_ID" runat="server" Value='<%#Eval("key_Id") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Role Name" HeaderStyle-CssClass="col-center" ItemStyle-CssClass="col-center">
<ItemTemplate>
<asp:Label ID="lblKeyword_name" runat="server" Text='<%#Eval("Keyword_name") %>' ItemStyle-Width="40%" HeaderStyle-Font-Bold="true" ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtKeyword_name" runat="server" Text='<%#Eval("Keyword_name") %>' MaxLength="50"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-CssClass="col-center" HeaderText="Action">
<ItemTemplate>
<asp:Button ID="btnEdit" runat="server" Text="Edit" CssClass="button-style" Width="100px" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="btnUpdate" runat="server" Text="Update" CssClass="button-style" CommandName="Update" />
<asp:Button ID="btnCancel" runat="server" Text="Cancel" CssClass="button-style" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
.CS Page
public void BindGridView()
{
try
{
MySqlConnection con = new MySqlConnection(conStr);
{
con.Open();
string str = "SELECT Sr_No,key_Id,Keyword_name,added_on FROM keyword_mst";
MySqlCommand cmd = new MySqlCommand(str, con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
grd.DataSource = ds;
grd.DataBind();
if (ds.Tables[0].Rows.Count > 0)
{
lblRecords.Text = "Total Record/s :" + " " + ds.Tables[0].Rows.Count.ToString();
lblRecords.Visible = true;
}
grd.DataSource = ds;
grd.DataBind();
con.Close();
}
}
catch (Exception)
{
throw;
}
}
protected void grd_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
grd.EditIndex = -1;
BindGridView();
}
protected void grd_RowEditing(object sender, GridViewEditEventArgs e)
{
grd.EditIndex = e.NewEditIndex;
BindGridView();
}
protected void grd_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
HiddenField IdNo = grd.Rows[e.RowIndex].FindControl("hdnkey_ID") as HiddenField;
TextBox KeywordName = grd.Rows[e.RowIndex].FindControl("txtKeyword_name") as TextBox;
string Query = "Update keyword_mst set Keyword_name='" + KeywordName.Text + "' where key_Id='" + IdNo.Value+"'";
MySqlConnection con = new MySqlConnection(conStr);
con.Open();
//updating the record
MySqlCommand cmd = new MySqlCommand(Query, con);
cmd.ExecuteNonQuery();
con.Close();
//Setting the EditIndex property to -1 to cancel the Edit mode in Gridview
grd.EditIndex = -1;
//Call ShowData method for displaying updated data
BindGridView();
}
protected void grd_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grd.PageIndex = e.NewPageIndex;
BindGridView();
}
Thursday, 7 September 2017
To replace special character using JavaScript
To replace special character using JavaScript
function replaceTextBoxValue(mystring)
{
return mystring.replace(/>/g, ">").replace(/</g, "<").replace(/'/g, "'");
}
Sunday, 3 September 2017
Display the ASCII Values of Numbers.
Display the ASCII Values of Numbers.
using System;
namespace PrintASCII
{
class PrintASCII
{
static void Main(string[] args)
{
for (int i =0; i <= 1000; i++)
{
System.Console.WriteLine("{0} = {1}", i, (char)i);
}
}
}
}
Swap two values using third variable.
Swap two values using third variable.
using System;
class swaping
{
public static void Main(string[] args)
{
int a,b,temp;
Console.WriteLine("Enter the value for a");
a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the value for b");
b=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Before swaping valus are:-");
Console.WriteLine("a=" +a);
Console.WriteLine("b="+b);
temp=a;
a=b;
b=temp;
Console.WriteLine("After swaping valus are:-");
Console.WriteLine("a=" +a);
Console.WriteLine("b="+b);
Console.Read();
}
}
Output:
Before:-
a=1
b=2
After:-
a=2
b=1
Swap two values with out using third variable.
Swap two values with out using third variable.
using System;
class swap
{
public static void Main(string[] args)
{
int a,b;
Console.WriteLine("Enter the value for a");
a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the value for b");
b=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Before swaping:-");
Console.WriteLine("a=" +a);
Console.WriteLine("b="+b);
a=a+b;
b=a-b;
a=a-b;
Console.WriteLine("After swaping:-");
Console.WriteLine("a=" +a);
Console.WriteLine("b="+b);
Console.Read();
}
}
output
before:-
a=1
b=2
After:-
a=2
b=1
Console Program for display name of Day when user input integer value using Switch Case
Console Program for display name of Day when user input integer value using Switch Case.
using System;
namespace code
{
class switchCase
{
public static void Main(string[] args)
{
string i;
Console.WriteLine("Enter Number Of Day");
i=(Console.ReadLine());
switch (i)
{
case "1":
{
Console.WriteLine("SUNDAY");
break;
}
case "2":
{
Console.WriteLine("MONDAY");
break;
}
case "3":
{
Console.WriteLine("TUESDAY");
break;
}
case "4":
{
Console.WriteLine("WEDNESDAY");
break;
}
case "5":
{
Console.WriteLine("THURSDAY");
break;
}
case "6":
{
Console.WriteLine("FRIDAY");
break;
}
case "7":
{
Console.WriteLine("SATURDAY");
break;
}
default:
{
Console.WriteLine("WRONG INPUT");
break;
}
}
}
}
}
Sunday, 27 August 2017
Thursday, 10 August 2017
To Replace Special Character to HTML tags using C# function:
To Replace Special Character to HTML tags using C# function:
public string ReplaceSpecialChars(string str)
{
if (str != null)
{
str = str.Replace("'", "'");
str = str.Replace("<", "<");
str = str.Replace(">", ">");
str = str.Replace(@"\", "\");
}
return str;
}
Saturday, 3 June 2017
Saturday, 27 May 2017
Wednesday, 24 May 2017
Friday, 5 May 2017
Friday, 28 April 2017
Login / Sign up using WEB METHOD
Login / Sign up using WEB METHOD
/*ADMIN MASTER for Project*/
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Admin.master.cs" Inherits="PictureGallery.Admin" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" style="background-image: URL(../Image/Dash_Background.jpg);">
<head runat="server">
<link href="Css/DashBoardCss.css" rel="stylesheet" />
<title>Picture Gallery</title>
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
<style>
.xyz {
float: right;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width: 100%">
<tr>
<td>
<div class="xyz">
<ul>
<li><a class="active" href="#home">Home</a>
</li>
<li><a href="#news">Gallery</a>
</li>
<li><a href="#My Profile" id="openDialog" >My Profile</a>
</li>
<li><a href="#about">About Us</a>
</li>
<li><a href="login.aspx">Log Out</a>
</li>
</ul>
</div>
</td>
</tr>
<tr>
<td>
<asp:ContentPlaceHolder ID="ContentPlaceHolder" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
LOGIN.ASPX PAGE
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="PictureGallery.login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" class="cover_pic">
<head runat="server">
<title>Picture Gallery</title>
<link href="Css/loginPage.css" rel="stylesheet" />
<style>
.textColor {
color: green;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script>
//function NewUserPopup() {
// var url = "NewUser.aspx";
// newwindow = window.open(url, 'name', 'width=400, height=320 left=400 top=300');
// if (window.focus) { newwindow.focus() }
//}
function fnValidate() {
var Name = document.getElementById("txtName").value;
var Email = document.getElementById("txtEmail").value;
var Password = document.getElementById("txtPass").value;
var DOB = document.getElementById("txtDOB").value;
var Gender = $('#radiogender input:checked').val();
var Address = document.getElementById("txtAddress").value;
var Mobile = document.getElementById("txtMobile").value;
if (Name == "") {
alert("Enter name");
document.getElementById("txtName").focus();
return false;
}
if (Email == "") {
alert("Enter Email");
document.getElementById("txtEmail").focus();
return false;
} if (Password == "") {
alert("Enter Password");
document.getElementById("txtPass").focus();
return false;
}
if (Gender == undefined) {
alert("Enter Gender");
$('#radiogender input:checked').focus();
return false;
} if (DOB == "") {
alert("Enter DOB");
document.getElementById("txtDOB").focus();
return false;
}
if (Address == "") {
alert("Enter Address");
document.getElementById("txtAddress").focus();
return false;
} if (Mobile == "") {
alert("Enter Mobile");
document.getElementById("txtMobile").focus();
return false;
}
save(Name, Email, Password, DOB, Gender, Address, Mobile);
}
/*Ajax function for Insert Data*/
function save(Name, Email, Password, DOB, Gender, Address, Mobile) {
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: 'login.aspx/Insert_Data',
data: "{'Name':'" + Name + "','Email':'" + Email + "','Password':'" + Password + "','DOB':'" + DOB + "','Gender':'" + Gender + "','Address':'" + Address + "','Mobile':'" + Mobile + "'}",
async: false,
success: function (response) {
alert("Record saved successfully..!!");
},
error: function () {
alert("Error");
}
});
}
$(function () {
$("#dialogBox").dialog({
autoOpen: false, modal: true,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$("#openDialog").on("click", function () {
$("#dialogBox").dialog("open");
});
});
function closeDialog() {
$("#dialogBox").dialog("close");
}
</script>
<style>
.ui-dialog {
height: auto;
width: 400px !important;
}
a {
color: blue !important;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div class="login_div">
<table class="login_form">
<tr>
<td colspan="2" style="color: red">
<asp:Label ID="lblMsg" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td class="textColor">User Name
</td>
<td>
<asp:TextBox ID="txtUserName" runat="server" CssClass="UserName"></asp:TextBox>
</td>
</tr>
<tr>
<td class="textColor">Password
</td>
<td>
<asp:TextBox ID="txtPassword" TextMode="Password" runat="server" CssClass="password"></asp:TextBox>
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnLogin" runat="server" Text="login" CssClass="buttoncss" OnClick="btnLogin_Click" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<a href="#" id="openDialog">NewUser</a>
<%-- <asp:LinkButton ID="LinkButton1" runat="server" Text="New User1" CssClass="dialog"></asp:LinkButton>
<asp:LinkButton ID="lnkButton" runat="server" Text="New User" OnClientClick="NewUserPopup();"></asp:LinkButton>--%>
</td>
</tr>
</table>
</div>
<div id="dialogBox">
<fieldset>
<legend style="color: darkblue; font-weight:bold">New User Signup</legend>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Label ID="Label1" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Name
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtName" runat="server" CssClass="textboxstyle"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
User Id
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtEmail" runat="server" CssClass="textboxstyle"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Password
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtPass" runat="server" CssClass="textboxstyle"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Gender
</asp:TableCell>
<asp:TableCell>
<asp:RadioButtonList ID="radiogender" runat="server" RepeatDirection="Horizontal">
<asp:ListItem Text="Male" Value="Male"></asp:ListItem>
<asp:ListItem Text="Female" Value="Female"></asp:ListItem>
</asp:RadioButtonList>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Date Of Birth
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtDOB" runat="server" CssClass="textboxstyle" TextMode="Date"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Address
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtAddress" runat="server" CssClass="textboxstyle" TextMode="MultiLine" Height="50px"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Mobile
</asp:TableCell>
<asp:TableCell>
<asp:TextBox ID="txtMobile" runat="server" CssClass="textboxstyle"></asp:TextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Center">
<asp:Button ID="btnSave" Text="Save" runat="server" CssClass="buttoncss" OnClientClick="return fnValidate();" />
<asp:Button ID="btnCancel" Text="Cancel" runat="server" OnClientClick="closeDialog();" CssClass="buttoncss" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</fieldset>
</div>
</form>
</body>
</html>
LOGIN.ASPX.CS PAGE
sing MySql.Data.MySqlClient;
using PictureGallery.BL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PictureGallery
{
public partial class login : System.Web.UI.Page
{
MySQLQuery obj = new MySQLQuery();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string query = "select User_Id from user_info_mst where User_Email_ID='" + txtUserName.Text + "' and User_Password='" + txtPassword.Text + "';";
DataSet i = obj.readData(query);
DataTable dt = new DataTable();
dt = i.Tables[0];
if (dt.Rows.Count> 0)
{
Session["User_Id"] = dt.Rows[0]["User_Id"].ToString();
Response.Redirect("HomePage.aspx");
}
else {
lblMsg.Text = "Invalid User Name or Password, Try Again!!!!!";
}
}
/* DATA Insert Using web Method*/
[WebMethod]
public static string Insert_Data(string Name, string Email, string Password, string DOB, string Gender, string Address, string Mobile)
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
try
{
con.Open();
MySqlCommand cmd = new MySqlCommand("insert into user_info_mst (UserName,User_Email_ID,User_Password,Gender,DOB,Address,Mobile) values ('" + Name + "','" + Email + "','" + Password + "','" + Gender + "','" + DOB + "','" + Address + "'," + Mobile + ")", con);
cmd.ExecuteNonQuery();
con.Close();
return "Success";
}
catch (Exception e)
{
return "failure";
}
}
}
}
/*BL which inherit to perform Mysql action*/
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
namespace PictureGallery.BL
{
public class MySQLQuery
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
public int ExecutQuery(string query)
{
con.Open();
MySqlCommand cmd = new MySqlCommand(query, con);
int i = cmd.ExecuteNonQuery();
con.Close();
return i;
}
public DataSet readData(string query)
{
con.Open();
MySqlCommand cmd = new MySqlCommand(query, con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet dt=new DataSet ();
da.Fill(dt);
con.Close();
return dt;
}
}
}
/*CSS for Login page*/
body {
}
.login_div {
border: solid;
border-color: green;
width: 45%;
margin-left: 55% ! important;
margin-top: 300px;
height: 200px;
border-radius: 25px;
background-image: Url(../Image/pic2.jpg);
background-size: 400px 200px;
}
.login_form {
margin-top: 10%;
margin-left: 25%;
}
.cover_pic {
background-image: Url(../Image/pic5.jpg);
background-size: 100% 1000px;
}
.UserName {
background-image: Url(../Image/userName.jpg);
background-size: 30px 20px;
background-repeat: no-repeat;
background-position: right;
}
.password {
background-image: Url(../Image/password.jpg);
background-size: 30px 20px;
background-repeat: no-repeat;
background-position: right;
}
.buttoncss {
width: 75px;
border-radius: 6px;
border-color: green;
}
/*Dashbord css*/
body {
}
ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: inherit;
}
li {
float: left;
}
li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
li Button:a {
background-color: purple;
}
/*common css*/
.buttoncss {
width: 75px;
border-radius: 6px;
border-color: green;
}
.textboxstyle {
height:15px;
color:gray;
font-size:small;
width:225px;
}
table tr td {
color:gray;
}
.div_Background {
background: darkgreen;
}
HOME.ASPX PAGE
<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.Master" AutoEventWireup="true" CodeBehind="HomePage.aspx.cs" Inherits="PictureGallery.HomePage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css" />
<script>
/*Function for open dialog box using JQUERY*/
$(function () {
$("#UserInfo").dialog({
autoOpen: false, modal: true,
show: {
effect: "blind",
duration: 1000
},
hide: {
effect: "explode",
duration: 1000
}
});
$("#openDialog").on("click", function () {
var getDate = fnGETEmpDetails();
$("#UserInfo").dialog("open");
});
});
/*Function for bind data using ajax*/
function fnGETEmpDetails() {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "HomePage.aspx/getDetails",
data: "{}",
dataType: "json",
success: achivedata,
error: function (result) {
alert("Error");
}
});
}
function achivedata(e) {
var datalist = e.d;
document.getElementById('<%=lblName.ClientID%>').innerText = datalist[0].empName;
document.getElementById('<%=lblUserId.ClientID%>').innerText = datalist[0].Email;
document.getElementById('<%=lblGender.ClientID%>').innerText = datalist[0].Gender;
document.getElementById('<%=lblDOB.ClientID%>').innerText = datalist[0].DOB;
document.getElementById('<%=lblAddress.ClientID%>').innerText = datalist[0].Address;
document.getElementById('<%=lblMobile.ClientID%>').innerText = datalist[0].Mobile;
}
function closeDialog() {
$("#UserInfo").dialog("close");
}
</script>
<style>
.ui-dialog {
height: auto;
width: 400px !important;
top: 60px !important;
margin-left: 60%;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder" runat="server">
<div id="UserInfo">
<fieldset>
<legend style="color: darkblue; font-weight: bold">My Profile</legend>
<asp:Table ID="Table1" runat="server">
<asp:TableRow>
<asp:TableCell>
Name
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblName" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
User Id
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblUserId" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Gender
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblGender" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Date Of Birth
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblDOB" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Address
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblAddress" runat="server"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
Mobile
</asp:TableCell>
<asp:TableCell>
<asp:Label ID="lblMobile" runat="server" ></asp:Label>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</fieldset>
</div>
</asp:Content>
HOME.ASPX.CS PAGE
(Data bind using Web Method)
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace PictureGallery
{
public partial class HomePage : System.Web.UI.Page
{
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
public static string userid = "";
protected void Page_Load(object sender, EventArgs e)
{
userid= Session["User_Id"].ToString();
}
/*Web Method Data bind and return as a Array*/
public class employee
{
public string empName { get; set; }
public string Email { get; set; }
public string DOB { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public string Mobile { get; set; }
}
[WebMethod]
public static employee[] getDetails()
{
List<employee> listobjEmp = new List<employee>();
MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
string qry = "select UserName,User_Email_ID,Gender,date_format(DOB,'%d-%b-%Y')as DOB,Address,Mobile from user_info_mst where User_Id=" + userid;
con.Open();
MySqlCommand cmd = new MySqlCommand(qry, con);
MySqlDataReader read = cmd.ExecuteReader();
employee empObj = new employee();
while (read.Read())
{
empObj.empName = read["UserName"].ToString();
empObj.Email = read["User_Email_ID"].ToString();
empObj.Gender = read["Gender"].ToString();
empObj.DOB = read["DOB"].ToString();
empObj.Address = read["Address"].ToString();
empObj.Mobile = read["Mobile"].ToString();
}
listobjEmp.Add(empObj);
con.Close();
return listobjEmp.ToArray();
}
}
}
Subscribe to:
Posts (Atom)