Q:- Mail sending code.?
Ans:-
protected void btnsend_Click(object sender, EventArgs e)
{
try
{
// string Smtp = ConfigurationSettings.AppSettings["SMTPADDRESS"].ToString();
//string Smtp = ConfigurationSettings.AppSettings["SMTPADDRESS"].ToString();
string frommailid = txtemail.Text;
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
//<" +txtfname.Text+ "> <" + txtlname.Text + ">
string str = txtfname.Text + " " + txtlname.Text;
string Smtp = Convert.ToString(ConfigurationManager.AppSettings["Hostname"]);
int SmtpPort = Convert.ToInt32(ConfigurationManager.AppSettings["smtpport"]);
string EmailFrom = Convert.ToString(ConfigurationManager.AppSettings["EmailFrom"]);
string EmailPassword = Convert.ToString(ConfigurationManager.AppSettings["EmailPassword"]);
//MailAddress fromAddress = new MailAddress(" " + str + " <" + frommailid + ">");
MailAddress fromAddress = new MailAddress(txtemail.Text);
smtpClient.Host = Smtp;
smtpClient.Credentials = new System.Net.NetworkCredential(EmailFrom, EmailPassword);
smtpClient.EnableSsl = true;
smtpClient.Port = SmtpPort;
message.From = fromAddress;
message.To.Add(EmailFrom);
message.IsBodyHtml = true;
//message.CC.Add(ccAddress);
//message.Subject = TextBox2.Text;
message.Subject = "Meisa Transportation Mail";
string strHTML;
strHTML = "<HTML xmlns='http://www.w3.org/1999/xhtml'> <head><title></title></head>";
strHTML += "<BODY>";
strHTML += "<table style='width:100%' cellpadding='2' cellspacing='2'><tr><td valign ='top'
{
try
{
// string Smtp = ConfigurationSettings.AppSettings["SMTPADDRESS"].ToString();
//string Smtp = ConfigurationSettings.AppSettings["SMTPADDRESS"].ToString();
string frommailid = txtemail.Text;
SmtpClient smtpClient = new SmtpClient();
MailMessage message = new MailMessage();
//<" +txtfname.Text+ "> <" + txtlname.Text + ">
string str = txtfname.Text + " " + txtlname.Text;
string Smtp = Convert.ToString(ConfigurationManager.AppSettings["Hostname"]);
int SmtpPort = Convert.ToInt32(ConfigurationManager.AppSettings["smtpport"]);
string EmailFrom = Convert.ToString(ConfigurationManager.AppSettings["EmailFrom"]);
string EmailPassword = Convert.ToString(ConfigurationManager.AppSettings["EmailPassword"]);
//MailAddress fromAddress = new MailAddress(" " + str + " <" + frommailid + ">");
MailAddress fromAddress = new MailAddress(txtemail.Text);
smtpClient.Host = Smtp;
smtpClient.Credentials = new System.Net.NetworkCredential(EmailFrom, EmailPassword);
smtpClient.EnableSsl = true;
smtpClient.Port = SmtpPort;
message.From = fromAddress;
message.To.Add(EmailFrom);
message.IsBodyHtml = true;
//message.CC.Add(ccAddress);
//message.Subject = TextBox2.Text;
message.Subject = "Meisa Transportation Mail";
string strHTML;
strHTML = "<HTML xmlns='http://www.w3.org/1999/xhtml'> <head><title></title></head>";
strHTML += "<BODY>";
strHTML += "<table style='width:100%' cellpadding='2' cellspacing='2'><tr><td valign ='top'
align ='left' style='border:#eee 1px solid;'>";
strHTML += "<table style='width:100%'>";
strHTML += "<tr><td valign ='top' align ='left' style='padding:6px 0 0 8px'>";
strHTML += "Description: " + txtcomments.Text + " <br> From: " + frommailid + "";
strHTML += "</table></td></tr></table>";
strHTML += "</BODY>";
strHTML += "</HTML>";
message.Body = strHTML;
smtpClient.Send(message);
}
catch (Exception ex)
{
}
}
strHTML += "<table style='width:100%'>";
strHTML += "<tr><td valign ='top' align ='left' style='padding:6px 0 0 8px'>";
strHTML += "Description: " + txtcomments.Text + " <br> From: " + frommailid + "";
strHTML += "</table></td></tr></table>";
strHTML += "</BODY>";
strHTML += "</HTML>";
message.Body = strHTML;
smtpClient.Send(message);
}
catch (Exception ex)
{
}
}
====================================================================
In web config file setting:-
---------------------------------------
using System.Net.Mail;
//using System.Web.Extensions;
using System.Web.Configuration;
---------------------------
<appSettings>
<add key="EmailFrom" value="contactus@meisatransportation.com"/>
<add key="EmailPassword" value="contactus123"/>
<add key="Hostname" value="smtpout.secureserver.net"/>
<add key="smtpport" value="80"/>
</appSettings>
protected void binddrp()
{
SqlDataAdapter adp = new SqlDataAdapter("write your query", con);
DataSet dtdseigi = new DataSet();
adp.Fill(dtdseigi);
drpupdateDesignation.DataSource = dtdseigi;
drpupdateDesignation.DataValueField = "id";
drpupdateDesignation.DataTextField = "name";
drpupdateDesignation.DataBind();
drpupdateDesignation.Items.Insert(0, "--Select Designation--");
}
<add key="EmailFrom" value="contactus@meisatransportation.com"/>
<add key="EmailPassword" value="contactus123"/>
<add key="Hostname" value="smtpout.secureserver.net"/>
<add key="smtpport" value="80"/>
</appSettings>
Q.Bind Dropdwonlist from database.?
Ans:-protected void binddrp()
{
SqlDataAdapter adp = new SqlDataAdapter("write your query", con);
DataSet dtdseigi = new DataSet();
adp.Fill(dtdseigi);
drpupdateDesignation.DataSource = dtdseigi;
drpupdateDesignation.DataValueField = "id";
drpupdateDesignation.DataTextField = "name";
drpupdateDesignation.DataBind();
drpupdateDesignation.Items.Insert(0, "--Select Designation--");
}
Q.Store procedure for insert into two table at same time.?
Ans:- set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
--
=============================================
-- Author: <Author,,Name>
-- Create date:
<Create Date,,>
-- Description: <Description,,>
--
=============================================
ALTER PROCEDURE [dbo].[SpRegistration]
(
@id int=null,
@U_Name nvarchar(50)=null,
@U_pwd nvarchar(50)=null,
@U_Email nvarchar(50)= null,
@U_Ph nvarchar(50)=null,
@U_Address nvarchar(50)=null,
@operation int=null
)
AS
begin transaction abc
BEGIN
SET NOCOUNT
ON;
-- Select
statements for procedure here
if(@operation=1)
begin
if exists(SELECT * from User_login where U_Name=@U_Name and U_pwd=@U_pwd)
select 'true' as UserExists
else
select 'False' as UserExists
end
if(@operation=2)
begin
--insert
statements for procedure here
declare @userid int
INSERT INTO Registration(U_Name,U_pwd,U_Email,U_Ph,U_Address)
VALUES(@U_Name, @U_pwd,@U_Email,@U_Ph, @U_Address )
set @userid =@@identity
insert
into User_login(Reg_Id, U_Name,U_pwd)
values(@userid,@U_Name,@U_pwd)
if(@@error !=0)
begin
rollback transaction abc
end
END
commit transaction abc
end
1. SELECT @@VERSION VersionInfo
Q.SQL SERVER – Get Server Version and Additional Info?
Ans:-
1. SELECT @@VERSION VersionInfo
GO
2. EXEC xp_msver
GO
Q. Read Excel sheet data and save into Sql Server Database.?
Ans:-
Q. Bind the dropdwon from the dataset.?
ANs:- objCompanyBusiness.BalanceCheckRequired =
CheckBalanceCheckingRequired.Checked == true ? "Y" : "N";
objCompanyBusiness.ForAllBranches =
CheckForAllBranches.Checked == true ? "Y" : "N";
OR
bool CH = Convert.ToBoolean(ResultSet.Rows[0]["ForAllBranches"].
ToString().Trim() == "Y" ? "true" : "false");
CheckForAllBranches.Checked = CH;
bool CH1 = Convert.ToBoolean(ResultSet.Rows[0]["BalanceCheckRequired"].
ToString().Trim() == "Y" ? "true" : "false");
CheckBalanceCheckingRequired.Checked = CH1;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Data;
public partial class Home : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=WINSERVER;Initial Catalog=test;User ID=IDSI;Password=idsi@centris");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void bind()
{
string query = "select empid,empname,address,photo,'View' [View] from empn";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
DataSet dt = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Close();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/upload/" + filename));
string qry = "insert into empn (empname,address,photo)values('" + empname.Text + "','" + eaddress.Text + "','" + filename + "')";
SqlCommand cmd = new SqlCommand(qry, con);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
{
Label1.Visible = true;
Label1.Text = "submit successfully";
bind();
}
}
else
{
Label1.Visible = true;
Label1.Text = "upload first!";
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
string query = "Delete from empn where empid= '" + id + "'";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("<script> confirm('want to delete?')</script>");
}
con.Close();
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
TextBox txt_name = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_empname");
TextBox txt_addr = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_adrr3");
string query = "update empn set empname='" + txt_name.Text + "', address='" + txt_addr.Text + "' where empid='" + id + "'";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("<script> alert('Updated successfully')</script>");
}
con.Close();
GridView1.EditIndex = -1;
bind();
}
}
=============================
for View image....
string id = Request.QueryString["id"].ToString();
string qry="select empid,empname,address,photo from empn where empid='"+id+"'";
SqlCommand cmd = new SqlCommand(qry, con);
con.Open();
SqlDataReader dr= cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text = dr[0].ToString();
Label2.Text = dr[1].ToString();
Label3.Text = dr[2].ToString();
Image1.ImageUrl = "~/upload/" + dr[3].ToString();
}
con.Close();
=============================
<asp:Image ID="img" runat="server" ImageUrl='<%#"~/upload/"+ Eval("photo") %>' Height="50px" Width="50px"/>
<script type="text/javascript" src="../js/BTCommon.js"></script>
<script src="../Jscript/WebLeadsGrid.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () { getData(); });</script>
<div class="offset0 " id="divEmpty" style="display: none;">
<div class="alert alert-block alert-info fade in">
<br />
<h4>
No web leads available.</h4>
<p>
</p>
<br />
</div>
</div>
<div id="Users">
<div id="flex1" style="display: none">
</div>
</div>
<div id="Edit" title="Edit Profile" style="display: none">
</div>
<div id="Delete" title="Delete web leads." style="display: none">
</div>
</div>
Q- Save image into the database.?Ans:-
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Data;
public partial class Home : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=WINSERVER;Initial Catalog=test;User ID=IDSI;Password=idsi@centris");
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();
}
}
protected void bind()
{
string query = "select empid,empname,address,photo,'View' [View] from empn";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
DataSet dt = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Close();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/upload/" + filename));
string qry = "insert into empn (empname,address,photo)values('" + empname.Text + "','" + eaddress.Text + "','" + filename + "')";
SqlCommand cmd = new SqlCommand(qry, con);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
if (i > 0)
{
Label1.Visible = true;
Label1.Text = "submit successfully";
bind();
}
}
else
{
Label1.Visible = true;
Label1.Text = "upload first!";
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
protected void GridView1_RowDeleting1(object sender, GridViewDeleteEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
string query = "Delete from empn where empid= '" + id + "'";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("<script> confirm('want to delete?')</script>");
}
con.Close();
bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
TextBox txt_name = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_empname");
TextBox txt_addr = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txt_adrr3");
string query = "update empn set empname='" + txt_name.Text + "', address='" + txt_addr.Text + "' where empid='" + id + "'";
SqlCommand cmd = new SqlCommand(query, con);
con.Open();
if (cmd.ExecuteNonQuery() > 0)
{
Response.Write("<script> alert('Updated successfully')</script>");
}
con.Close();
GridView1.EditIndex = -1;
bind();
}
}
=============================
for View image....
string id = Request.QueryString["id"].ToString();
string qry="select empid,empname,address,photo from empn where empid='"+id+"'";
SqlCommand cmd = new SqlCommand(qry, con);
con.Open();
SqlDataReader dr= cmd.ExecuteReader();
while (dr.Read())
{
Label1.Text = dr[0].ToString();
Label2.Text = dr[1].ToString();
Label3.Text = dr[2].ToString();
Image1.ImageUrl = "~/upload/" + dr[3].ToString();
}
con.Close();
=============================
<asp:Image ID="img" runat="server" ImageUrl='<%#"~/upload/"+ Eval("photo") %>' Height="50px" Width="50px"/>
Q. JavaScript Validation multiple fields in a form.?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
{function validateForm()
var x=document.forms["myForm"]["name"].value;
if (x==null || x=="")
{
alert("Name must be filled out");
return false;
}
var y=document.forms["myForm"]["password"].value;
{
if (y==null || y=="")
alert("Password name must be filled out");
return false;
}
</script>
</head>
<body>
<form name="myForm" action="demo_form.asp" onsubmit="return validateForm()" method="post">
Name*: <input type="text" name="name"> <br>
Password*: <input type="password" name="password"><br>
Email: <input type="text" name="email"><br>
<input type="submit" value="Submit">
</form>
</body>
</html>
========================================================================
Q:- Jquery flexigrid in asp net c#
Ans:- First create a .js file and use the code in your .js and modified it as per your requirement.
=======================================================================
/// <summary>
/// Created By:- Jitendra Kumar Maurya
/// Bind web leads List.
/// </summary>
function getData() {
$("#flex1").flexigrid
(
{
url: 'GetWebLeads.aspx',
dataType: 'xml',
colModel: [
{ display: '#', name: 'Sl_No', width: 30, sortable: false, align: 'right' },
{ display: '' + ' ' + '<input type="checkbox" onclick="selectALL();" id="selectall" />', name: 'SelectAll', width: 50, sortable: false, align: 'center' },
{ display: 'Id', name: 'Id', width: 100, sortable: true, align: 'left', hide: true },
{ display: 'First Name', name: 'FirstName', width: 100, sortable: true, align: 'left' },
{ display: 'Last Name', name: 'LastName', width: 100, sortable: true, align: 'left' },
{ display: 'Email', name: 'Email', width: 150, sortable: true, align: 'left' },
{ display: 'Phone', name: 'Phone', width: 80, sortable: true, align: 'left' },
{ display: 'CompanyName', name: 'CompanyName', width: 200, sortable: true, align: 'left' },
{ display: 'Job Title', name: 'JobTitle', width: 200, sortable: true, align: 'left' },
{ display: 'Industry', name: 'Industry', width: 60, sortable: true, align: 'center' },
{ display: 'Country', name: 'Country', width: 70, sortable: true, align: 'center' },
{ display: 'RefWebsite', name: 'RefWebsite', width: 100, sortable: true, align: 'left' },
{ display: 'Created On', name: 'CreatedOn', width: 100, sortable: true, align: 'left' },
{ display: 'List Name', name: 'Name', width: 100, sortable: true, align: 'left' }
],
buttons: [
{ name: 'AddtoList', bclass: 'AddtoList', onpress: test },
{ separator: true },
{ name: 'Delete', bclass: 'Delete', onpress: test },
{ separator: true },
{ name: 'Refresh', bclass: 'Refresh', onpress: Refresh, align: 'right' },
{ separator: true }
],
searchitems: [
{ display: 'First Name', name: 'FirstName' },
{ display: 'Last Name', name: 'LastName' },
{ display: 'Company Name', name: 'CompanyName' }
],
sortname: "CreatedOn",
sortorder: "desc",
usepager: true,
align: 'left',
useRp: true,
rp: 15,
showTableToggleBtn: false,
resizable: false,
width: 'Auto',
height: 500
}
);
}
function Refresh() {
window.location.href = "WebLeads.aspx";
}
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "WebLeads.aspx/GetWebleadLists",
data: "{}",
dataType: "json",
success: function (data) {
$.each(data.d, function (key, value) {
$("#drpSelectListName").append($("<option></option>").val(value.UserID).html(value.Name));
});
},
error: function (result) {
console.log(result);
}
});
});
function test(com, grid) {
if (com == 'New') {
// window.location.href = "Campaigns.aspx?sm=CampaignInfo";
}
else if (com == 'AddtoList') {
var temp = 0;
var Id = '';
$("#flex1").find("tr").each(function () {
$(this).find("input:checkbox").each(function () {
if ($(this).prop("checked") == true) {
temp += 1;
Id += "," + $(this).attr("id");
}
});
});
if (temp == 0) {
$('#AddtoList').html('');
$('#AddtoList').append("please select a Web Lead");
$('#AddtoList').show();
$('#AddtoList').dialog({
resizable: false,
height: 180,
width: 390,
modal: true,
buttons: {
"Okay": function () {
$(this).dialog("close");
}
}
});
}
else {
window.location.href = "WebLeads.aspx?Id=AddtoList&CompanyId1=" + Id + "";
}
}
var temp = 0;
var Id = '';
$("#flex1").find("tr").each(function () {
$(this).find("input:checkbox").each(function () {
if ($(this).prop("checked") == true) {
temp += 1;
Id += "," + $(this).attr("id");
}
});
});
if (com == 'Delete') {
if (temp == 0) {
$('#Delete').html('');
$('#Delete').append("Please select a Web lead..!");
$('#Delete').show();
$('#Delete').dialog({
resizable: false,
height: 180,
width: 390,
modal: true,
buttons: {
"Okay": function () {
$(this).dialog("close");
}
}
});
}
else {
var Id = '';
$("#flex1").find("tr").each(function () {
$(this).find("input:checkbox").each(function () {
if ($(this).prop("checked") == true) {
temp += 1;
Id += "," + $(this).attr("id");
}
});
});
$('#Delete').html('');
$('#Delete').append("Are You sure! Want to Delete this Web Lead..!");
$('#Delete').show();
$('#Delete').dialog({
resizable: false,
height: 180,
width: 390,
modal: true,
buttons: {
"Yes": function confrim() {
$.ajax({
url: "GetWebLeads.aspx/Delete_WebLead?Id=" + Id,
data: {},
type: "POST",
dataType: "json",
contentType: "application/json;charset=utf-8",
success: function (data) {
if (data.d == 'success') {
window.location.href = "WebLeads.aspx?delete=success";
}
else {
Delete_failed();
}
},
failure: function () {
Delete_failed();
}
});
},
"No": function () {
$(this).dialog("close");
}
}
});
}
}
}
function selectALL() {
if ($("#selectall").prop("checked")) {
$(".flexigrid").find("tr").each(function () {
$(this).find("input:checkbox").each(function () {
if ($(this).attr("id") != "selectall") {
$(this).attr("checked", true);
}
});
});
}
else {
$(".flexigrid").find("tr").each(function () {
$(this).find("input:checkbox").each(function () {
if ($(this).attr("id") != "selectall") {
$(this).attr("checked", false);
}
});
});
}
}
function Deleted() {
var $alertdiv = $('<div id = "alertmsg"/>');
$alertdiv.text("Web Lead deleted successfully");
$alertdiv.bind('click', function () {
$(this).slideUp(200);
});
$(document.body).append($alertdiv);
$("#alertmsg").slideDown("slow");
setTimeout(function () { $alertdiv.slideUp(200) }, 3000);
}
function Delete_failed() {
var $alertdiv = $('<div id = "alertmsg"/>');
$alertdiv.text("Web Lead deletion failed.. !Try again");
$alertdiv.bind('click', function () {
$(this).slideUp(200);
});
$(document.body).append($alertdiv);
$("#alertmsg").slideDown("slow");
setTimeout(function () { $alertdiv.slideUp(200) }, 3000);
}
function success() {
var $alertdiv = $('<div id = "alertmsg"/>');
$alertdiv.text("Web Lead Updated successfully..!");
$alertdiv.bind('click', function () {
$(this).slideUp(200);
});
$(document.body).append($alertdiv);
$("#alertmsg").slideDown("slow");
setTimeout(function () { $alertdiv.slideUp(200) }, 3000);
}
function error() {
var $alertdiv = $('<div id = "alertmsg"/>');
$alertdiv.text("Web Lead not Deleted. Please try again..!");
$alertdiv.bind('click', function () {
$(this).slideUp(200);
});
$(document.body).append($alertdiv);
$("#alertmsg").slideDown("slow");
setTimeout(function () { $alertdiv.slideUp(200) }, 3000);
=======================================================================
----> Call this .js file and function file into your main code behind page.
<script src="../js/flexigrid.js" type="text/javascript"></script><script type="text/javascript" src="../js/BTCommon.js"></script>
<script src="../Jscript/WebLeadsGrid.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () { getData(); });</script>
----> Add this also for flexigrid view
<div id="maindiv" class="box5 form-bg offsettop1"><div class="offset0 " id="divEmpty" style="display: none;">
<div class="alert alert-block alert-info fade in">
<br />
<h4>
No web leads available.</h4>
<p>
</p>
<br />
</div>
</div>
<div id="Users">
<div id="flex1" style="display: none">
</div>
</div>
<div id="Edit" title="Edit Profile" style="display: none">
</div>
<div id="Delete" title="Delete web leads." style="display: none">
</div>
</div>
=======================================================================
----> Call a seprate page for loading the flexi grid. Follow the sample code.
private string _filterfield = string.Empty;
private string _filterValue = string.Empty;
private readonly DateTime _startDate = DateTime.UtcNow;
private readonly DateTime _endDate = DateTime.UtcNow;
protected void Page_Load(object sender, EventArgs e)
{
// var Divid = int.Parse(HttpContext.Current.Request.QueryString["Divid"]);
//int Userid = int.Parse(HttpContext.Current.Request.QueryString["UserID"]);
try
{
var totalRec = 0;
var page = int.Parse(Request.Form["page"]);
var rp = int.Parse(Request.Form["rp"]);
var sortname = Request.Form["sortname"];
var sortorder = Request.Form["sortorder"];
_filterfield = Request.Form["qtype"];
_filterValue = Request.Form["query"];
if (page == 0)
page = 1;
if (rp == 0)
rp = 10;
var sort = String.Format("{0} {1}", sortname, sortorder);
var start = ((page - 1) * rp) + 1;
if (page > 1)
rp = (page * rp);
Response.ClearHeaders();
Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
Response.AppendHeader("Last-Modified", string.Format("{0} {1}", DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString()));
Response.AppendHeader("Cache-Control", "no-cache, must-revalidate");
Response.AppendHeader("Pragma", "no-cache");
Response.AppendHeader("Content-type", "text/xml");
// Generating XML Data
var companyId = Convert.ToInt32(HttpContext.Current.Session["CompanyID"]);
var data = GetWebLeads(companyId, _filterfield, _filterValue, sort, start, rp);
foreach (var items in data)
{
totalRec = Convert.ToInt32(items.TotalRecords);
}
var xmlDoc = new XDocument(
new XDeclaration("1.0", "utf-8", "yes"),
new XElement("rows",
new XElement("page", page.ToString(CultureInfo.InvariantCulture)),
new XElement("total", totalRec),
data.Select(row => new XElement("row", new XAttribute("Id", row.Id),
new XElement("cell", row.Rownumber),
new XElement("cell", String.Format(" <input type='checkbox' id='{0}' />", row.Id)),
new XElement("cell", row.Id),
new XElement("cell", row.FirstName),
new XElement("cell", row.LastName),
new XElement("cell", row.Email),
new XElement("cell", row.Phone),
new XElement("cell", row.CompanyName),
new XElement("cell", row.JobTitle),
new XElement("cell", row.Industry),
new XElement("cell", row.Country),
new XElement("cell", row.RefWebsite),
new XElement("cell", row.CreatedOn),
new XElement("cell", row.Name)
)
)
)
);
Response.Write(xmlDoc);
}
catch (SqlException ex)
{
var line = ex.StackTrace.Substring(ex.StackTrace.LastIndexOf(' ') + 1);
var pageName = ex.StackTrace.Substring(ex.StackTrace.LastIndexOf('\\') + 1, (ex.StackTrace.LastIndexOf(':') - ex.StackTrace.LastIndexOf('\\')) - 1);
var obj = new ExceptionHandle();
if (ex.TargetSite.DeclaringType != null)
obj.SendMail("Sql Exception", ex.Message, ex.TargetSite.Name, pageName, ex.TargetSite.DeclaringType.Namespace, ex.TargetSite.MemberType.ToString(), line);
}
catch (Exception ex)
{
var line = ex.StackTrace.Substring(ex.StackTrace.LastIndexOf(' ') + 1);
var pageName = ex.StackTrace.Substring(ex.StackTrace.LastIndexOf('\\') + 1, (ex.StackTrace.LastIndexOf(':') - ex.StackTrace.LastIndexOf('\\')) - 1);
var obj = new ExceptionHandle();
if (ex.TargetSite.DeclaringType != null)
obj.SendMail("RunTime Exception", ex.Message, ex.TargetSite.Name, pageName, ex.TargetSite.DeclaringType.Namespace, ex.TargetSite.MemberType.ToString(), line);
}
Response.End();
}
-- =============================================
-- Author: <Jitendra Kumar Maurya>
-- Create date: <Create 05.02.2014,,>
-- Description: <Get the Web leads list,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_GetWebLeads]
@CompanyId int,
@FilterField varchar(100),
@FilterValue varchar(100),
@rowstart int=1,
@rowend int=15,
@sortexp varchar(100),
@StartDate datetime,
@EndDate datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
--CONVERT(DATETIME, CreatedDate,103)
SET NOCOUNT ON;
IF (@FilterField='')
BEGIN
SELECT Id
, FirstName
, LastName
, Email
, Phone
, CompanyName
, JobTitle
, Industry
, Country
, RefWebsite
, CONVERT(varchar(12), CreatedOn,101) as CreatedOn
, TotalRec
, rownumber
, Name
FROM
(SELECT WL.Id
, WL.FirstName
, WL.LastName
, WL.Email
, WL.Phone
, WL.CompanyName
, WL.JobTitle
, WL.Industry
, WL.Country
, WL.RefWebsite
, CONVERT(varchar(12), CreatedOn,101) as CreatedOn
, ML.Name
, row_number() OVER (
ORDER BY CASE
WHEN @sortexp = 'FirstName asc' THEN
FirstName
END ASC,
CASE
WHEN @sortexp = 'FirstName desc' THEN
FirstName
END DESC,
CASE
WHEN @sortexp = 'LastName asc' THEN
LastName
END ASC,
CASE
WHEN @sortexp = 'LastName desc' THEN
LastName
END DESC,
CASE
WHEN @sortexp = 'Email asc' THEN
Email
END ASC,
CASE
WHEN @sortexp = 'Email desc' THEN
Email
END DESC,
CASE
WHEN @sortexp = 'Phone asc' THEN
Phone
END ASC,
CASE
WHEN @sortexp = 'Phone desc' THEN
Phone
END DESC,
CASE
WHEN @sortexp = 'CompanyName asc' THEN
CompanyName
END ASC,
CASE
WHEN @sortexp = 'CompanyName desc' THEN
CompanyName
END DESC,
CASE
WHEN @sortexp = 'JobTitle asc' THEN
JobTitle
END ASC,
CASE
WHEN @sortexp = 'JobTitle desc' THEN
JobTitle
END DESC,
CASE
WHEN @sortexp = 'Industry asc' THEN
Industry
END ASC,
CASE
WHEN @sortexp = 'Industry desc' THEN
Industry
END DESC ,
CASE
WHEN @sortexp = 'Country asc' THEN
Country
END ASC,
CASE
WHEN @sortexp = 'Country desc' THEN
Country
END DESC,
CASE
WHEN @sortexp = 'RefWebsite asc' THEN
RefWebsite
END ASC,
CASE
WHEN @sortexp = 'RefWebsite desc' THEN
RefWebsite
END DESC,
CASE
WHEN @sortexp = 'CreatedOn asc' THEN
CreatedOn
END ASC,
CASE
WHEN @sortexp = 'CreatedOn desc' THEN
CreatedOn
END DESC,
CASE
WHEN @sortexp = 'Name asc' THEN
ML.Name
END ASC,
CASE
WHEN @sortexp = 'Name desc' THEN
ML.Name
END DESC
) AS rownumber
, count(WL.Id) OVER () AS TotalRec
FROM
[CT_WebLeads] WL inner join CT_mailinglist ML
on
ML.Name= WL.ListId WHERE
WL.CompanyId=@CompanyId
AND WL.IsDelete=0
) AS a
WHERE
rownumber BETWEEN @rowstart AND @rowend
END
ELSE
BEGIN
SELECT Id
, FirstName
, LastName
, Email
, Phone
, CompanyName
, JobTitle
, Industry
, Country
, RefWebsite
, CONVERT(varchar(12), CreatedOn,101) as CreatedOn
, TotalRec
, rownumber
, Name
FROM
(SELECT WL.Id
, WL.FirstName
, WL.LastName
, WL.Email
, WL.Phone
, WL.CompanyName
, WL.JobTitle
, WL.Industry
, WL.Country
, WL.RefWebsite
, CONVERT(varchar(12), CreatedOn,101) as CreatedOn
, ML.Name
,row_number() OVER (
ORDER BY CASE
WHEN @sortexp = 'FirstName asc' THEN
WL.FirstName
END ASC,
CASE
WHEN @sortexp = 'FirstName desc' THEN
WL.FirstName
END DESC,
CASE
WHEN @sortexp = 'LastName asc' THEN
WL.LastName
END ASC,
CASE
WHEN @sortexp = 'LastName desc' THEN
WL.LastName
END DESC,
CASE
WHEN @sortexp = 'Email asc' THEN
WL.Email
END ASC,
CASE
WHEN @sortexp = 'Email desc' THEN
WL.Email
END DESC,
CASE
WHEN @sortexp = 'Phone asc' THEN
WL.Phone
END ASC,
CASE
WHEN @sortexp = 'Phone desc' THEN
WL.Phone
END DESC,
CASE
WHEN @sortexp = 'CompanyName asc' THEN
WL.CompanyName
END ASC,
CASE
WHEN @sortexp = 'CompanyName desc' THEN
WL.CompanyName
END DESC,
CASE
WHEN @sortexp = 'JobTitle asc' THEN
WL.JobTitle
END ASC,
CASE
WHEN @sortexp = 'JobTitle desc' THEN
WL.JobTitle
END DESC,
CASE
WHEN @sortexp = 'Industry asc' THEN
WL.Industry
END ASC,
CASE
WHEN @sortexp = 'Industry desc' THEN
WL.Industry
END DESC ,
CASE
WHEN @sortexp = 'Country asc' THEN
WL.Country
END ASC,
CASE
WHEN @sortexp = 'Country desc' THEN
WL.Country
END DESC,
CASE
WHEN @sortexp = 'RefWebsite asc' THEN
WL.RefWebsite
END ASC,
CASE
WHEN @sortexp = 'RefWebsite desc' THEN
WL.RefWebsite
END DESC,
CASE
WHEN @sortexp = 'CreatedOn asc' THEN
WL.CreatedOn
END ASC,
CASE
WHEN @sortexp = 'CreatedOn desc' THEN
WL.CreatedOn
END DESC,
CASE
WHEN @sortexp = 'Name asc' THEN
ML.Name
END ASC,
CASE
WHEN @sortexp = 'Name desc' THEN
ML.Name
END DESC
) AS rownumber
, count(WL.Id) OVER () AS TotalRec
FROM
[CT_WebLeads] WL Left outer join CT_mailinglist ML
on
ML.ID= WL.ListId WHERE
WL.CompanyId=@CompanyId
AND WL.IsDelete=0 AND (
CASE @FilterField
WHEN 'FirstName' THEN
FirstName
WHEN 'LastName' THEN
LastName
WHEN 'CompanyName' THEN
CompanyName
END LIKE '%' + @FilterValue + '%')
) AS a
WHERE
rownumber BETWEEN @rowstart AND @rowend
END
END
// Store procedure for flexi grid view.
-- =============================================
-- Author: <Jitendra Kumar Maurya>
-- Create date: <Create 05.02.2014,,>
-- Description: <Get the Web leads list,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_GetWebLeads]
@CompanyId int,
@FilterField varchar(100),
@FilterValue varchar(100),
@rowstart int=1,
@rowend int=15,
@sortexp varchar(100),
@StartDate datetime,
@EndDate datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
--CONVERT(DATETIME, CreatedDate,103)
SET NOCOUNT ON;
IF (@FilterField='')
BEGIN
SELECT Id
, FirstName
, LastName
, Phone
, CompanyName
, JobTitle
, Industry
, Country
, RefWebsite
, CONVERT(varchar(12), CreatedOn,101) as CreatedOn
, TotalRec
, rownumber
, Name
FROM
(SELECT WL.Id
, WL.FirstName
, WL.LastName
, WL.Email
, WL.Phone
, WL.CompanyName
, WL.JobTitle
, WL.Industry
, WL.Country
, WL.RefWebsite
, CONVERT(varchar(12), CreatedOn,101) as CreatedOn
, ML.Name
, row_number() OVER (
ORDER BY CASE
WHEN @sortexp = 'FirstName asc' THEN
FirstName
END ASC,
CASE
WHEN @sortexp = 'FirstName desc' THEN
FirstName
END DESC,
CASE
WHEN @sortexp = 'LastName asc' THEN
LastName
END ASC,
CASE
WHEN @sortexp = 'LastName desc' THEN
LastName
END DESC,
CASE
WHEN @sortexp = 'Email asc' THEN
END ASC,
CASE
WHEN @sortexp = 'Email desc' THEN
END DESC,
CASE
WHEN @sortexp = 'Phone asc' THEN
Phone
END ASC,
CASE
WHEN @sortexp = 'Phone desc' THEN
Phone
END DESC,
CASE
WHEN @sortexp = 'CompanyName asc' THEN
CompanyName
END ASC,
CASE
WHEN @sortexp = 'CompanyName desc' THEN
CompanyName
END DESC,
CASE
WHEN @sortexp = 'JobTitle asc' THEN
JobTitle
END ASC,
CASE
WHEN @sortexp = 'JobTitle desc' THEN
JobTitle
END DESC,
CASE
WHEN @sortexp = 'Industry asc' THEN
Industry
END ASC,
CASE
WHEN @sortexp = 'Industry desc' THEN
Industry
END DESC ,
CASE
WHEN @sortexp = 'Country asc' THEN
Country
END ASC,
CASE
WHEN @sortexp = 'Country desc' THEN
Country
END DESC,
CASE
WHEN @sortexp = 'RefWebsite asc' THEN
RefWebsite
END ASC,
CASE
WHEN @sortexp = 'RefWebsite desc' THEN
RefWebsite
END DESC,
CASE
WHEN @sortexp = 'CreatedOn asc' THEN
CreatedOn
END ASC,
CASE
WHEN @sortexp = 'CreatedOn desc' THEN
CreatedOn
END DESC,
CASE
WHEN @sortexp = 'Name asc' THEN
ML.Name
END ASC,
CASE
WHEN @sortexp = 'Name desc' THEN
ML.Name
END DESC
) AS rownumber
, count(WL.Id) OVER () AS TotalRec
FROM
[CT_WebLeads] WL inner join CT_mailinglist ML
on
ML.Name= WL.ListId WHERE
WL.CompanyId=@CompanyId
AND WL.IsDelete=0
) AS a
WHERE
rownumber BETWEEN @rowstart AND @rowend
END
ELSE
BEGIN
SELECT Id
, FirstName
, LastName
, Phone
, CompanyName
, JobTitle
, Industry
, Country
, RefWebsite
, CONVERT(varchar(12), CreatedOn,101) as CreatedOn
, TotalRec
, rownumber
, Name
FROM
(SELECT WL.Id
, WL.FirstName
, WL.LastName
, WL.Email
, WL.Phone
, WL.CompanyName
, WL.JobTitle
, WL.Industry
, WL.Country
, WL.RefWebsite
, CONVERT(varchar(12), CreatedOn,101) as CreatedOn
, ML.Name
,row_number() OVER (
ORDER BY CASE
WHEN @sortexp = 'FirstName asc' THEN
WL.FirstName
END ASC,
CASE
WHEN @sortexp = 'FirstName desc' THEN
WL.FirstName
END DESC,
CASE
WHEN @sortexp = 'LastName asc' THEN
WL.LastName
END ASC,
CASE
WHEN @sortexp = 'LastName desc' THEN
WL.LastName
END DESC,
CASE
WHEN @sortexp = 'Email asc' THEN
WL.Email
END ASC,
CASE
WHEN @sortexp = 'Email desc' THEN
WL.Email
END DESC,
CASE
WHEN @sortexp = 'Phone asc' THEN
WL.Phone
END ASC,
CASE
WHEN @sortexp = 'Phone desc' THEN
WL.Phone
END DESC,
CASE
WHEN @sortexp = 'CompanyName asc' THEN
WL.CompanyName
END ASC,
CASE
WHEN @sortexp = 'CompanyName desc' THEN
WL.CompanyName
END DESC,
CASE
WHEN @sortexp = 'JobTitle asc' THEN
WL.JobTitle
END ASC,
CASE
WHEN @sortexp = 'JobTitle desc' THEN
WL.JobTitle
END DESC,
CASE
WHEN @sortexp = 'Industry asc' THEN
WL.Industry
END ASC,
CASE
WHEN @sortexp = 'Industry desc' THEN
WL.Industry
END DESC ,
CASE
WHEN @sortexp = 'Country asc' THEN
WL.Country
END ASC,
CASE
WHEN @sortexp = 'Country desc' THEN
WL.Country
END DESC,
CASE
WHEN @sortexp = 'RefWebsite asc' THEN
WL.RefWebsite
END ASC,
CASE
WHEN @sortexp = 'RefWebsite desc' THEN
WL.RefWebsite
END DESC,
CASE
WHEN @sortexp = 'CreatedOn asc' THEN
WL.CreatedOn
END ASC,
CASE
WHEN @sortexp = 'CreatedOn desc' THEN
WL.CreatedOn
END DESC,
CASE
WHEN @sortexp = 'Name asc' THEN
ML.Name
END ASC,
CASE
WHEN @sortexp = 'Name desc' THEN
ML.Name
END DESC
) AS rownumber
, count(WL.Id) OVER () AS TotalRec
FROM
[CT_WebLeads] WL Left outer join CT_mailinglist ML
on
ML.ID= WL.ListId WHERE
WL.CompanyId=@CompanyId
AND WL.IsDelete=0 AND (
CASE @FilterField
WHEN 'FirstName' THEN
FirstName
WHEN 'LastName' THEN
LastName
WHEN 'CompanyName' THEN
CompanyName
END LIKE '%' + @FilterValue + '%')
) AS a
WHERE
rownumber BETWEEN @rowstart AND @rowend
END
END
Q.Reverse a string program.
ReplyDeleteLike:-string=bangalore
Output string= bearnogla.
protected void btnSubmit_Click(object sender, EventArgs e)
{
string str = TextBox1.Text.Trim();
int count = 0;
ArrayList strArray = new ArrayList();
StringBuilder result = new StringBuilder();
// Adding to ArrayList
for (int i = 0; i < str.Length; i++)
{
strArray.Add(str.Substring(i, 1));
}
// Taking Count
if (strArray.Count % 2 != 0)
{
count = strArray.Count / 2;
count = count + 1;
}
else
{
count = strArray.Count / 2;
}
//Arranging
for (int i = 0; i < count; i++)
{
result.Append(strArray[i]);
strArray.Reverse();
result.Append(strArray[i]);
strArray.Reverse();
}
//
if (strArray.Count % 2 != 0)
{
TextBox2.Text = result.ToString().Substring(0, strArray.Count);
}
else
{
TextBox2.Text = result.ToString();
}
}
using System;
ReplyDeleteusing System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCTEST111.Models;
namespace MVCTEST111.Controllers
{
public class EmpController : Controller
{
//
// GET: /Emp/
SampleJitendraEntities sampobj = new SampleJitendraEntities();
UserReg tableobj = new UserReg();
public ActionResult Index()
{
return View(sampobj.UserRegs.ToList());
}
//
// GET: /Emp/Details/5
public ActionResult Details(int id)
{
return View();
}
//
// GET: /Emp/Create
public ActionResult Create()
{
return View();
}
//
// POST: /Emp/Create
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create([Bind(Exclude="Id")]UserReg objtale )
{
try
{
// TODO: Add insert logic here
sampobj.AddToUserRegs(objtale);
sampobj.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Emp/Edit/5
public ActionResult Edit(int id)
{
var res = (from r in sampobj.UserRegs where r.Id == id select r).FirstOrDefault();
return View(res);
}
//
// POST: /Emp/Edit/5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(UserReg tb)
{
try
{
// TODO: Add update logic here
var res = (from r in sampobj.UserRegs where r.Id == tb.Id select r).FirstOrDefault();
sampobj.ApplyCurrentValues(res.EntityKey.EntitySetName, tb);
sampobj.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
//
// GET: /Emp/Delete/5
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult Delete(int id)
{
var res = (from r in sampobj.UserRegs where r.Id == id select r).FirstOrDefault();
return View(res);
}
//
// POST: /Emp/Delete/5
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Delete(UserReg tb)
{
try
{
// TODO: Add delete logic here
var res = (from r in sampobj.UserRegs where r.Id == tb.Id select r).FirstOrDefault();
sampobj.DeleteObject(res);
sampobj.SaveChanges();
return RedirectToAction("Index");
}
catch
{
return View();
}
}
}
}
For jobs please visit on this site and fwd your resums.
ReplyDeletehttp://click2employment.com/ContactUs.aspx
Q.JQuery validation for TextBox.?
ReplyDelete=========================
$(function () {
$("#<%=btnSubmit.ClientID %>").click(function () {
var summary = "";
summary += isvalidUsername();
summary += isvalidEmailid();
summary += isvalidAddress();
summary += isvalidateprofession();
summary += isvalidateMobileno();
if (summary != "") {
alert(summary);
return false;
}
else {
return true;
}
})
})
function isvalidUsername() {
var temp = $("#<%=txtName.ClientID %>").val();
if (temp == "") {
return ("Please enter user name..!" + "\n");
}
else {
return "";
}
}
function isvalidEmailid() {
var temp = $("#<%=txtEmailId.ClientID %>").val();
if (temp == "") {
return ("Please enter email id..!" + "\n");
}
else {
return "";
}
}
function isvalidAddress() {
var temp = $("#<%=txtAddress.ClientID %>").val();
if (temp == "") {
return ("Please enter address..!" + "\n");
}
else {
return "";
}
}
function isvalidateprofession() {
var temp = $("#<%=txtProfession.ClientID %>").val();
if (temp == "") {
return ("Please enter the profession..!" + "\n");
}
else {
return "";
}
}
function isvalidateMobileno() {
var temp = $("#<%=txtMobNo.ClientID %>").val();
if (temp == "") {
return ("Please enter the mobile no..!"+"\n");
}
else {
return "";
}
}
For study and code go for this url:- http://www.webcodeexpert.com/
ReplyDeleteFollow Link for FlexiGridView:--\
ReplyDeletehttp://www.raihaniqbal.net/blog/2008/06/using-flexigrid-in-your-aspnet-application/