<div style="float:right">
Shalvin P D
</div>
Thursday, February 6, 2014
Asp .Net Balance Updating with Session Variable
In the Blog Creating and Consuming Class Library in C#, Object Initializer I have demonstrated creating a simple Bank with Deposit and Withdraw functionality in Windows Forms.
Creating that in Windows Forms is straight forward.
When it comes to Web Forms (Asp .Net) you have to maintain sessions to get the same functionality.
Creating that in Windows Forms is straight forward.
When it comes to Web Forms (Asp .Net) you have to maintain sessions to get the same functionality.
int Balance = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowBal();
}
else
{
if (Session["Balance"] != null)
Balance = (int)Session["Balance"];
}
}
private void ShowBal()
{
lblCurBal.Text = Balance.ToString();
txtAmount.Text = "";
txtAmount.Focus();
}
protected void btnDeposit_Click(object sender, EventArgs e)
{
Balance += Int32.Parse(txtAmount.Text);
Session["Balance"] = Balance;
ShowBal();
}
protected void btnWithras_Click(object sender, EventArgs e)
{
Balance -= Int32.Parse(txtAmount.Text);
Session["Balance"] = Balance;
ShowBal();
}
.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="Label1" runat="server" Text="Balance"></asp:Label>
<asp:Label ID="lblCurBal" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Amount"></asp:Label>
<asp:TextBox ID="txtAmount" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnDeposit" runat="server" OnClick="btnDeposit_Click" Text="Deposit" />
<asp:Button ID="btnWithras" runat="server" OnClick="btnWithras_Click" Text="Withdraw" />
</form>
</body>
</html>
Courtesy : Arjun Pandavath, Speridian TechnologiesMonday, January 27, 2014
ASP .Net GridView Editing
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating">
<Columns>
<asp:BoundField DataField="Contactid" HeaderText="CId" ReadOnly="True" />
<asp:BoundField DataField="contactname" HeaderText="name" />
<asp:BoundField DataField="Phone" HeaderText="Phone" />
<asp:CommandField ShowEditButton="True" />
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
using System.Configuration;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
SqlConnection cnn = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GetData();
}
}
private void GetData()
{
using (cnn = new SqlConnection(ConfigurationManager.AppSettings.Get("Cnn")))
{
SqlDataAdapter da = new SqlDataAdapter("select ContactId, ContactName, Phone from Contacts", cnn);
DataSet ds = new DataSet();
da.Fill(ds, "Co");
GridView1.DataSource = ds.Tables["Co"];
DataBind();
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
GetData();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
using (cnn = new SqlConnection(ConfigurationManager.AppSettings.Get("Cnn")))
{
cnn.Open();
string id = GridView1.Rows[e.RowIndex].Cells[0].Text;
string name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string phone = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string strSql = "update Contacts set ContactName = '" + name + "', phone = '" +
phone + "' where ContactId = " + id;
SqlCommand cmd = new SqlCommand(strSql, cnn);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
GetData();
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
GetData();
}
}
Saturday, January 25, 2014
C# Method Overloading
public void Display()
{
Response.Write("Hello " + "<br/>");
}
public void Display(string Name)
{
Response.Write("Hello " + Name + "<br/>");
}
public void Display(string Name, string Location)
{
Response.Write("Hello " + Name + " located at " + Location + "<br/>");
}
protected void Button1_Click(object sender, EventArgs e)
{
Display();
}
protected void Button2_Click(object sender, EventArgs e)
{
Display("Aiju");
}
protected void Button3_Click(object sender, EventArgs e)
{
Display("Sarath", "Trissur");
}
C# Abstract Class
public abstract class CalcAb
{
public abstract int Add(int i, int j);
public int Subtract(int i, int j)
{
return i - j;
}
}
public class Calc : CalcAb
{
public override int Add(int i, int j)
{
return i + j;
}
}
protected void Page_Load(object sender, EventArgs e)
{
Calc c = new Calc();
Response.Write(c.Add(78, 56));
Response.Write("<br/>");
Response.Write(c.Subtract(78, 67));
}
Friday, May 17, 2013
Monday, March 4, 2013
Kodiswaran March 3rd Question and Answers
1. Finger in which ink in applied after election - left index finger.
2. Musical instrument associated with Pandit Ravishankar -Sithar.
3. Number of chessmen in a standard chessboard -32.
4. Average body temperature of human being - 37
5. MP from Alappey who became Civil Aviation Minister on Oct 29 2012 - K C
Venugopal
6. ICC Cricket 2015 hosts - Australia and New Zealand
7. Pakshipathalam in Bhahmagiri hills is located at - Vayanad
http://en.wikipedia.org/wiki/Brahmagiri_(hill)
8. Kerala Sahithya Academy Award recepient for the work 'Or Pidi Nellikka'-
Edasseri
9. Number of Rasas in Navarasas - 9
10. According to Mahabharath Keechakan was killed by - Bhiman
Subscribe to:
Posts (Atom)

