private void CalcTotal(string _price)
{
try
{
runningTotal += Decimal.Parse(_price);
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.ToString());
}
}
private decimal runningTotal = 00;
private int index = 0;
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CalcTotal(e.Row.Cells[2].Text);
}
else if (e.Row.RowType == DataControlRowType.Footer)
{
e.Row.Cells[1].Text = "Total :";
e.Row.Cells[2].Text = String.Format("{0:c}", Convert.ToDecimal(runningTotal)); //Show total qty
runningTotal = 00;
index = 0;
}
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.ToString());
}
}
ব্লগ সংরক্ষাণাগার
বুধবার, ১৮ আগস্ট, ২০১০
শুক্রবার, ১৩ আগস্ট, ২০১০
***ASP.NET MVC 2: Model Validation and Client side validation.
***ASP.NET MVC 2: Model Validation and Client side validation
# Persisting to a Database
# Enabling Validation in model with ASP.NET MVC 2 and DataAnnotations
[MetadataType (typeof (EmployeeInfo))]
public class EmployeeInfo
{
private String empID;
[DisplayName("Employee ID")]
[StringLength(20,ErrorMessage="Can't be longer than 20")]
[Required (ErrorMessage="Must enter ID")]
public string EmpID
{
get { return empID; }
set { empID = value; }
}
private string empName;
[StringLength (50,ErrorMessage="Can't Be Longer than 50 char")]
[DisplayName("Employee Name")]
[Required (ErrorMessage="Must Enter")]
public string EmpName
{
get { return empName; }
set { empName = value; }
}
private DateTime date;
[DisplayName("Joing Date")]
public DateTime Date
{
get { return date; }
set { date = value; }
}
private decimal salary;
[DisplayName ("Salary")]
[Range (1000.00,100000.00,ErrorMessage="Number Must Entered Between 1000.00 To 100000.00")]
public decimal Salary
{
get { return salary; }
set { salary = value; }
}
}
# Create the EmployeeInfoController page and in Controller Page take the following steps-
• Right click on Controller folder and click on Controller to create a controller
• After that the follow dialog box appeared And then click on Add button.
public ActionResult Create()
{
return View();
}
HRMEntities entity = new HRMEntities();
//
// POST: /EmployeeInfo/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
EmployeeInformation employee = new EmployeeInformation();
employee.EmployeeId = collection[0].ToString();
employee.EmployeeName = collection[1].ToString();
employee.Salary = Convert.ToDecimal(collection[3].ToString());
employee.JoiningDate = Convert.ToDateTime(collection[2].ToString());
entity.AddToEmployeeInformations(employee);
return RedirectToAction("Create");
}
catch
{
return View();
}
}
# Create the view page and take the following steps
<h2>Create </h2>
<% Html.EnableClientValidation(); %>
<%: Html.ValidationSummary(true) %>
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields </legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.EmpID) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.EmpID) %>
<%: Html.ValidationMessageFor(model => model.EmpID) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.EmpName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.EmpName) %>
<%: Html.ValidationMessageFor(model => model.EmpName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Date) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Date) %>
<%: Html.ValidationMessageFor(model => model.Date) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Salary) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Salary) %>
<%: Html.ValidationMessageFor(model => model.Salary) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
• Click right button on Controller Create Method and add a view
• Click on Add View then will create the following page and the design view code is as follows-
# After that run and test
• After that add the following two link above the tag-
<h2>Create </h2>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"> </script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"> </script>
# Persisting to a Database
# Enabling Validation in model with ASP.NET MVC 2 and DataAnnotations
[MetadataType (typeof (EmployeeInfo))]
public class EmployeeInfo
{
private String empID;
[DisplayName("Employee ID")]
[StringLength(20,ErrorMessage="Can't be longer than 20")]
[Required (ErrorMessage="Must enter ID")]
public string EmpID
{
get { return empID; }
set { empID = value; }
}
private string empName;
[StringLength (50,ErrorMessage="Can't Be Longer than 50 char")]
[DisplayName("Employee Name")]
[Required (ErrorMessage="Must Enter")]
public string EmpName
{
get { return empName; }
set { empName = value; }
}
private DateTime date;
[DisplayName("Joing Date")]
public DateTime Date
{
get { return date; }
set { date = value; }
}
private decimal salary;
[DisplayName ("Salary")]
[Range (1000.00,100000.00,ErrorMessage="Number Must Entered Between 1000.00 To 100000.00")]
public decimal Salary
{
get { return salary; }
set { salary = value; }
}
}
# Create the EmployeeInfoController page and in Controller Page take the following steps-
• Right click on Controller folder and click on Controller to create a controller
• After that the follow dialog box appeared And then click on Add button.
public ActionResult Create()
{
return View();
}
HRMEntities entity = new HRMEntities();
//
// POST: /EmployeeInfo/Create
[HttpPost]
public ActionResult Create(FormCollection collection)
{
try
{
// TODO: Add insert logic here
EmployeeInformation employee = new EmployeeInformation();
employee.EmployeeId = collection[0].ToString();
employee.EmployeeName = collection[1].ToString();
employee.Salary = Convert.ToDecimal(collection[3].ToString());
employee.JoiningDate = Convert.ToDateTime(collection[2].ToString());
entity.AddToEmployeeInformations(employee);
return RedirectToAction("Create");
}
catch
{
return View();
}
}
# Create the view page and take the following steps
<h2>Create </h2>
<% Html.EnableClientValidation(); %>
<%: Html.ValidationSummary(true) %>
<% using (Html.BeginForm()) {%>
<fieldset>
<legend>Fields </legend>
<div class="editor-label">
<%: Html.LabelFor(model => model.EmpID) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.EmpID) %>
<%: Html.ValidationMessageFor(model => model.EmpID) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.EmpName) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.EmpName) %>
<%: Html.ValidationMessageFor(model => model.EmpName) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Date) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Date) %>
<%: Html.ValidationMessageFor(model => model.Date) %>
</div>
<div class="editor-label">
<%: Html.LabelFor(model => model.Salary) %>
</div>
<div class="editor-field">
<%: Html.TextBoxFor(model => model.Salary) %>
<%: Html.ValidationMessageFor(model => model.Salary) %>
</div>
<p>
<input type="submit" value="Create" />
</p>
</fieldset>
<% } %>
• Click right button on Controller Create Method and add a view
• Click on Add View then will create the following page and the design view code is as follows-
# After that run and test
• After that add the following two link above the tag-
<h2>Create </h2>
<script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"> </script>
<script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"> </script>
মঙ্গলবার, ৩ আগস্ট, ২০১০
Common Quary Execution in C#.net
///
/// Summary description for CommonQueryExecution
///
public class CommonQueryExecution
{
public bool flag = false;
public string querry = string.Empty;
private string returnString = string.Empty;
private SqlConnection con = null;
private SqlCommand cmd = null;
private SqlDataAdapter da = null;
private SqlDataReader dr = null;
private string strCon = ConfigurationManager.ConnectionStrings["BDConnectionString"].ToString();
///
/// used to execute all Querry statement.
///
/// param name="data"
///dataset
public DataSet ExecuteQuerry(string data)
{
con = new SqlConnection(strCon);
da = new SqlDataAdapter(data,con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
///
/// used to execute all non querry statement.
///
/// param name="data"
///dataset
public bool ExecuteNonQuerry(string data)
{
con = new SqlConnection(strCon);
cmd = new SqlCommand(data, con);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (cmd.ExecuteNonQuery() > 0)
{
flag = true;
}
else
{
flag = false;
}
if (con.State == ConnectionState.Open)
{
con.Close();
}
return flag;
}
///
///This function is used to check any record is exists or not
///
public bool IsValueExits(string data)
{
con = new SqlConnection(strCon);
cmd = new SqlCommand();
cmd.CommandText = data;
cmd.Connection = con;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
flag = true;
}
else
{
flag = false;
}
if (con.State == ConnectionState.Open)
{
con.Close();
}
return flag;
}
}
/// Summary description for CommonQueryExecution
///
public class CommonQueryExecution
{
public bool flag = false;
public string querry = string.Empty;
private string returnString = string.Empty;
private SqlConnection con = null;
private SqlCommand cmd = null;
private SqlDataAdapter da = null;
private SqlDataReader dr = null;
private string strCon = ConfigurationManager.ConnectionStrings["BDConnectionString"].ToString();
///
/// used to execute all Querry statement.
///
/// param name="data"
///
public DataSet ExecuteQuerry(string data)
{
con = new SqlConnection(strCon);
da = new SqlDataAdapter(data,con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
///
/// used to execute all non querry statement.
///
/// param name="data"
///
public bool ExecuteNonQuerry(string data)
{
con = new SqlConnection(strCon);
cmd = new SqlCommand(data, con);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (cmd.ExecuteNonQuery() > 0)
{
flag = true;
}
else
{
flag = false;
}
if (con.State == ConnectionState.Open)
{
con.Close();
}
return flag;
}
///
///This function is used to check any record is exists or not
///
public bool IsValueExits(string data)
{
con = new SqlConnection(strCon);
cmd = new SqlCommand();
cmd.CommandText = data;
cmd.Connection = con;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
dr = cmd.ExecuteReader();
if (dr.HasRows)
{
flag = true;
}
else
{
flag = false;
}
if (con.State == ConnectionState.Open)
{
con.Close();
}
return flag;
}
}
In asp.net how to short data in a gridview using Linq
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public static int a = 2;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataClassesDataContext db = new DataClassesDataContext();
IQueryable student = from s in db.StudentInformations
select s;
GridView1.DataSource = student;
GridView1.DataBind();
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (a % 2 == 0)
{
DataClassesDataContext db = new DataClassesDataContext();
IQueryable studentInformation = (from s in db.StudentInformations
select s).OrderByDescending(s => s.Student_ID);
GridView1.DataSource = studentInformation;
GridView1.DataBind();
e.Cancel = true;
a++;
}
else
{
DataClassesDataContext db = new DataClassesDataContext();
IQueryable studentInformation = (from s in db.StudentInformations
select s);
GridView1.DataSource = studentInformation;
GridView1.DataBind();
e.Cancel = true;
a++;
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
public static int a = 2;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataClassesDataContext db = new DataClassesDataContext();
IQueryable
select s;
GridView1.DataSource = student;
GridView1.DataBind();
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (a % 2 == 0)
{
DataClassesDataContext db = new DataClassesDataContext();
IQueryable
select s).OrderByDescending(s => s.Student_ID);
GridView1.DataSource = studentInformation;
GridView1.DataBind();
e.Cancel = true;
a++;
}
else
{
DataClassesDataContext db = new DataClassesDataContext();
IQueryable
select s);
GridView1.DataSource = studentInformation;
GridView1.DataBind();
e.Cancel = true;
a++;
}
}
}
How to work with Ajax Modal Pop Up Window in asp.net
এতে সদস্যতা:
পোস্টগুলি (Atom)