You are on page 1of 29

Ex. No: 6 : Develop a Web Application using C#.NET and ASP.NET for a Bank.

Date: The BANK Database should consist of following tables:


tbl_Bank (BankID: int, BankName: string), tbl_Branch (BranchID: int, BankID:
int, BranchName: string), tbl_Account (AccountNo:int, BankID: int, BranchID: int,
CustomerName: string, Address: string, ContactNo: int, Balance: real)
(Note: AccountNo and BankID together is a composite primary key).
The master page of this web application should contain hyperlinks to New Bank
Entry, New Branch Entry (of selected Bank), New Customer Entry (based on branch
and bank) and Report Generation.
The hyperlinks should navigate to respective content pages. These content pages
provide the fields for respective data entry. The reports should be generated (display
in grid) as below:
1. Display all records of particular bank.
2. Display all records of a branch of particular bank.
3. The balance should be displayed for the entered account number (Bank and
Branch areinput through ComboBox controls and Account number is input
through TextBox).
Aim:

Alogorithm:
Form Designs.
Master page
Programs:
Master Page code Design code:

<%@MasterLanguage="C#"AutoEventWireup="true"CodeFile="MasterPage.master.cs
"Inherits="MasterPa ge"%>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0


Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title></title>
<styletype="text/css">
.style1
{
text-align: center;
}
.style2
{
font-family: Arial,Helvetica,sans-serif;
}
.style3
{
font-family: Arial,Helvetica,sans-serif; color: #990000;
}
.style4
{
color: #990000;
}
</style>

</head>
<body>
<formid="form1"runat="server">
<divstyle="height: 79px; background-color: #FFCC00;">
</div>
<divstyle="width: 202px; height: 539px; float:left; background-color: #FF00FF;"
class="style1">
<strong>MENU<br/>
<br/>
</strong><spanclass="style2">
<ahref="NewBankEntry.aspx"><strong><spanclass="style4">NewBankEntry</span></
strong></a></span
><strong><br class="style3"/>
<br/>
<brclass="style2"/>
</strong><spanclass="style2">
<ahref="NewBranchEntry.aspx"><strong><spanclass="style4">NewBranchEntry</spa
n></strong></a></ span><strong><br
class="style3"/>
<br/>
<brclass="style2"/>
</strong><spanclass="style2"><strong><spanclass="style4"><ahref="NewCustomerEn
try.aspx">NewCu stomerEntry</a></span></strong></span><br/>
<br/>
<ahref="DisplayAllRecordOfBank.aspx"><strong>Display All Record Of
Bank</strong></a><strong><br/>
</strong>
<br/>
<strong>
<ahref="DisplayBranchDetails.aspx">DisplayBranchDetails</a></strong><br/>
<br/>
<ahref="DisplayBalance.aspx">Display Balance</a></div>
<divstyle="height: 542px">
<asp:ContentPlaceHolderid="head"runat="server">
</asp:ContentPlaceHolder>
</div>
<divstyle="height: 48px; background-color: #9933FF;">
</div>
</form>
</body>
</html>
Form Designs.
New Bank Entry
New Book Entry Design Code:

<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventW
ireup="true"CodeFil e="NewBankEntry.aspx.cs"Inherits="NewBankEntry"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h2class="style1"style="color: #FF0000">New Bank Entry</h2>
<fieldset>
<tablestyle="width: 59%; height: 96px;"border="0"align="center">
<tr>
<tdstyle="width: 810px; text-align: right"> Bank ID</td>
<tdstyle="width: 578px">
<asp:TextBoxID="TextBox1"runat="server"Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<tdstyle="width: 810px; text-align: right">
Bank Name</td>
<tdstyle="width: 578px">
<asp:TextBoxID="TextBox2"runat="server"Width="200px"></asp:TextBox>
</td>
</tr>
<tr>
<tdstyle="width: 810px"> &nbsp;</td>
<tdstyle="width: 578px"> &nbsp;</td>
</tr>
<tr>
<tdstyle="width: 810px"> &nbsp;</td>
<tdstyle="width: 578px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:ButtonID="Button1"runat="server"Text="Submit"Width="100px" style="color:
#FF0000"onclick="Button1_Click"/>
</td>
</tr>
</table>
</fieldset>
</asp:Content>
Aspx code:
using System;
using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Data.SqlClient;
publicpartialclassNewBankEntry : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{

}
protectedvoid Button1_Click(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
con.Open();
string query = "insert into tbl_Bank(BankID,BankName)
values("+TextBox1.Text+",'"+TextBox2.Text+"')"; SqlCommand cmd =
newSqlCommand(query,con);
int i = cmd.ExecuteNonQuery(); if (i > 0)
{
Response.Write("<script language='javascript'>alert('insertion successful')</script>");
}

else

{
Response.Write("<script language='javascript'>alert('insertion

failed')</script>");
}
TextBox1.Text = ""; TextBox2.Text = "";
}
}
Form Designs.
New Branch Entry
New Branch Entry Design code

<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventW
ireup="true"CodeFil e="NewBranchEntry.aspx.cs"Inherits="NewBranchEntry"%>

<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;&nbsp;&nbsp;
<spanstyle="color: #FF0000">New Branch Entry</span></h1>
<fieldset>
<tablestyle="width: 75%"align="center">
<tr>
<tdstyle="width: 159px; text-align: right;"> Branch ID</td>
<tdstyle="width: 474px">
<asp:TextBoxID="TextBox1"runat="server"Width="200px"Height="25px"></asp:Text
Box>
</td>
</tr>
<tr>
<tdstyle="width: 159px; text-align: right;"> Bank ID</td>
<tdstyle="width: 474px">
<asp:DropDownListID="DropDownList1"runat="server"Width="200px"Height="25px"
DataSourceID="SqlDataSource1"DataTextField="BankID"DataValueField="BankID">
<asp:ListItem>Select Bank ID</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource1"runat="server" ConnectionString="<%$
ConnectionStrings:bankDBConnectionString %>" SelectCommand="SELECT
[BankID] FROM [tbl_Bank]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<tdstyle="width: 159px; text-align: right;"> Branch Name</td>
<tdstyle="width: 474px">
<asp:TextBoxID="TextBox2"runat="server"Width="200px"Height="25px"></asp:Text
Box>
</td>
</tr>
<tr>
<tdstyle="width: 159px; text-align: right;"> &nbsp;</td>
<tdstyle="width: 474px"> &nbsp;</td>
</tr>
<tr>
<tdstyle="width: 159px; text-align: right;"> &nbsp;</td>
<tdstyle="width: 474px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
<asp:ButtonID="Button1"runat="server"Text="Submit"BackColor="Red"
Width="100px"onclick="Button1_Click"/>
</td>
</tr>
</table>
</fieldset>
</asp:Content>

Aspx code:

using System;
using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Data.SqlClient;
publicpartialclassNewBranchEntry : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{

}
protectedvoid Button1_Click(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
con.Open();
string query = "insert into tbl_Branch(BranchID,BankID,BranchName) values(" +
TextBox1.Text + ","+DropDownList1.SelectedValue+",'" + TextBox2.Text + "')";
SqlCommand cmd = newSqlCommand(query, con); int i = cmd.ExecuteNonQuery();
if (i > 0)
{

Response.Write("<script language='javascript'>alert('insertion successful')</script>");


}

else

{
Response.Write("<script language='javascript'>alert('insertion

failed')</script>");
}
TextBox1.Text = ""; TextBox2.Text = "";
}
}
Form Designs.
New Customer Entry
New Customer Entry Design code:

<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventW
ireup="true"CodeFil e="NewCustomerEntry.aspx.cs"Inherits="NewCustomerEntry"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h1style="color:
#FF0000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n
bsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nb
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; New Customer
Entry</h1>
<fieldset>
<tablealign="center"style="width: 78%">
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Account Number:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_acc"runat="server"Width="200px"Height="25px"></asp:T
extBox>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Bank ID:</b></td>
<tdstyle="width: 363px">
<asp:DropDownListID="DropDownList_bid"runat="server"Width="200px"
Height="25px"DataSourceID="SqlDataSource1"DataTextField="BankID"
DataValueField="BankID">
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource1"runat="server" ConnectionString="<%$
ConnectionStrings:bankDBConnectionString %>" SelectCommand="SELECT
[BankID] FROM [tbl_Bank]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Branch ID:</b></td>
<tdstyle="width: 363px">
<asp:DropDownListID="DropDownList_brachId"runat="server"Width="200px"
Height="25px"DataSourceID="SqlDataSource2"DataTextField="BranchID"
DataValueField="BranchID">
</asp:DropDownList>
<asp:SqlDataSourceID="SqlDataSource2"runat="server" ConnectionString="<%$
ConnectionStrings:bankDBConnectionString %>" SelectCommand="SELECT
[BranchID] FROM [tbl_Branch]"></asp:SqlDataSource>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Customer Name:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_custnm"runat="server"Width="200px"Height="25px"></a
sp:TextBox>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Address:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_add"runat="server"Width="200px"Height="25px"></asp:T
extBox>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Contact No:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_Con"runat="server"Width="200px"Height="25px"></asp:
TextBox>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;">
<b>Balance:</b></td>
<tdstyle="width: 363px">
<asp:TextBoxID="TextBox_bal"runat="server"Width="200px"Height="25px"></asp:T
extBox>
</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;"> &nbsp;</td>
<tdstyle="width: 363px"> &nbsp;</td>
</tr>
<tr>
<tdstyle="width: 219px; text-align: right; color: #FF0000;"> &nbsp;</td>
<tdstyle="width: 363px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
<asp:ButtonID="Button1"runat="server"BackColor="Red"Text="Submit"
Width="100px"onclick="Button1_Click"/>
</td>
</tr>
</table>
</fieldset>
</asp:Content>
Aspx Code:

using System;
using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Data.SqlClient;
publicpartialclassNewCustomerEntry : System.Web.UI.Page
{
protectedvoid Button1_Click(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
con.Open();
string query = "insert into
tbl_Account(AccountNo,BankID,BranchID,CustomerName,Address,ContactNo,Balanc
e)
values("+TextBox_acc.Text+","+DropDownList_bid.SelectedValue+","+DropDownList
_brachId.Selecte
dValue+",'"+TextBox_custnm.Text+"','"+TextBox_add.Text+"',"+TextBox_Con.Text+"
,"+TextBox_bal. Text+")";
SqlCommand cmd = newSqlCommand(query, con); int i = cmd.ExecuteNonQuery();
if (i > 0)
{
Response.Write("<script language='javascript'>alert('insertion successful')</script>");
}
else
{
Response.Write("<script language='javascript'>alert('insertion

failed')</script>");
}
TextBox_acc.Text = ""; TextBox_custnm.Text = ""; TextBox_add.Text = "";
TextBox_Con.Text = ""; TextBox_bal.Text = "";
}
}
Output:
Display all records of particular bank
Design code to Display all records of particular bank

<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventW
ireup="true"CodeFil
e="DisplayAllRecordOfBank.aspx.cs"Inherits="DisplayAllRecordOfBank"%>

<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&
nbsp;&nbsp;&nbsp;&nbsp
;&nbsp;&nbsp;&nbsp;&nbsp; Display All Record of Particular Bank</h1>

&nbsp;<asp:LabelID="Label1"runat="server"
style="font-weight: 700; text-align: right; color: #FF0000" Text="Select The
Bank"></asp:Label>
:<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"onselectedindex
changed=" DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br/>
<br/>
<br/>
<asp:GridViewID="GridView_details"runat="server"BackColor="White"
BorderColor="#CC9966"BorderStyle="None"BorderWidth="1px"CellPadding="4" style="text-
align: center"Width="380px">
<FooterStyleBackColor="#FFFFCC"ForeColor="#330099"/>
<HeaderStyleBackColor="#990000"Font-Bold="True"ForeColor="#FFFFCC"/>
<PagerStyleBackColor="#FFFFCC"ForeColor="#330099"HorizontalAlign="Center"/>
<RowStyleBackColor="White"ForeColor="#330099"/>
<SelectedRowStyleBackColor="#FFCC66"Font-Bold="True"ForeColor="#663399"/>
<SortedAscendingCellStyleBackColor="#FEFCEB"/>
<SortedAscendingHeaderStyleBackColor="#AF0101"/>
<SortedDescendingCellStyleBackColor="#F6F0C0"/>
<SortedDescendingHeaderStyleBackColor="#7E0000"/>
</asp:GridView>
<br/>
</asp:Content>
Aspx code:

using System;
using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data;
publicpartialclassDisplayAllRecordOfBank : System.Web.UI.Page
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
SqlDataAdapter da;
SqlCommand cmd;
//string query;

protectedvoid Page_Load(object sender, EventArgs e)


{
if (!IsPostBack)
{
con.Open();
string query = "select BankName from tbl_Bank "; cmd = newSqlCommand(query,
con);
SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read())
{
DropDownList1.Items.Add(dr[0].ToString());
}
con.Close(); gvBankDetail();
}
}
privatevoid gvBankDetail()
{
try
{
con.Open();
string query = "select *from tbl_Bank";
cmd = newSqlCommand(query,con); da = newSqlDataAdapter(cmd);
DataSet ds = newDataSet();
da.Fill(ds); GridView_details.DataSource = ds; GridView_details.DataBind();
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}

protectedvoid DropDownList1_SelectedIndexChanged(object sender, EventArgs e)


{
try
{
con.Open();

string query = "select *from tbl_Bank where


BankName='"+DropDownList1.SelectedItem+"'"; cmd = newSqlCommand(query, con);
da = newSqlDataAdapter(cmd); DataSet ds = newDataSet();
da.Fill(ds); GridView_details.DataSource = ds; GridView_details.DataBind();
con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
Display all records of a branch of particular bank.
Design code to Display all records of a branch of particular bank

<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventW
ireup="true"CodeFil
e="DisplayBranchDetails.aspx.cs"Inherits="DisplayBranchDetails"%>
<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<h1>Display Branch Detail</h1>
<asp:LabelID="Label1"runat="server"Text="Select the BankName"></asp:Label>
:<asp:DropDownListID="DropDownList1"runat="server"AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
<br/>
<br/>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
<br/>
</asp:Content>

Aspx code:

using System;
using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data;
publicpartialclassDisplayBranchDetails : System.Web.UI.Page
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
SqlDataAdapter da;
SqlCommand cmd;
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
string query = "select BankName from tbl_Bank "; cmd = newSqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read())
{
DropDownList1.Items.Add(dr[0].ToString());
}
con.Close(); gvBankDetail();
}
}
privatevoid gvBankDetail()
{
try
{
con.Open();
string query = "select *from tbl_Bank,tbl_Branch where
tbl_Bank.BankID=tbl_Branch.BankID"; cmd = newSqlCommand(query, con);
da = newSqlDataAdapter(cmd); DataSet ds = newDataSet();
da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); con.Close();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
protectedvoid DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{ try
{
con.Open();
string query = "select *from tbl_Bank,tbl_Branch where
tbl_Bank.BankID=tbl_Branch.BankID and tbl_Bank.BankName='" +
DropDownList1.SelectedItem + "'";
cmd = newSqlCommand(query, con); da = newSqlDataAdapter(cmd);
DataSet ds = newDataSet();
da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind(); con.Close();
}
catch (Exception ex){
Response.Write(ex.Message);
}
}
}
Display all records of a branch of particular bank
Design Code to display the balance for the entered account number

<%@PageTitle=""Language="C#"MasterPageFile="~/MasterPage.master"AutoEventW
ireup="true"CodeFil e="DisplayBalance.aspx.cs"Inherits="DisplayBalance"%>

<asp:ContentID="Content1"ContentPlaceHolderID="head"Runat="Server">
<tablestyle="width: 78%; height: 98px; vertical-align: middle; text-align: center;"
align="center">
<tr>
<tdstyle="width: 118px">
Account number </td>
<tdstyle="width: 155px">
<asp:TextBoxID="TextBox1"runat="server"Width="200px"></asp:TextBox>
</td>
<td> &nbsp;</td>
</tr>
<tr>
<tdstyle="width: 118px">

Bank ID</td>
<tdstyle="width: 155px">
<asp:DropDownListID="DropDownList1"runat="server"Width="200px">
</asp:DropDownList>
</td>
<td> &nbsp;</td>
</tr>
<tr>
<tdstyle="width: 118px">
Branch ID</td>
<tdstyle="width: 155px">
<asp:DropDownListID="DropDownList2"runat="server"Width="200px">
</asp:DropDownList>
</td>
<td> &nbsp;</td>
</tr>
<tr>
<tdstyle="width: 118px"> &nbsp;</td>
<tdstyle="width: 155px">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;
<asp:ButtonID="Button1"runat="server"Text="Display"Width="100px"
onclick="Button1_Click"/>
</td>
<td> &nbsp;</td>
</tr>
</table>
<asp:GridViewID="GridView1"runat="server">
</asp:GridView>
</asp:Content>

Aspx code:

using System;
using System.Collections.Generic; using System.Linq;
using System.Web; using System.Web.UI;
using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Data;

publicpartialclassDisplayBalance : System.Web.UI.Page
{
SqlConnection con = newSqlConnection("Data Source=DHANANJAY-PC;Initial
Catalog=bankDB;User ID=sa;Password=123;Pooling=False");
SqlDataAdapter da;
SqlCommand cmd;
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();

string query = "select BankID from tbl_Bank "; cmd = newSqlCommand(query, con);
SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read())
{
DropDownList1.Items.Add(dr[0].ToString());
}
con.Close();
}
if (!IsPostBack)
{
con.Open();
string query = "select BranchID from tbl_Branch ";

cmd = newSqlCommand(query, con); SqlDataReader dr = cmd.ExecuteReader(); while


(dr.Read())
{
DropDownList2.Items.Add(dr[0].ToString());
}
con.Close();
}

}
protectedvoid Button1_Click(object sender, EventArgs e)
{
con.Open();
string query = "select *from tbl_Account where BranchID=" +
DropDownList2.SelectedValue + "and BankID=" + DropDownList1.SelectedItem + "
and AccountNo=" +TextBox1.Text+"";

cmd = newSqlCommand(query, con); da = newSqlDataAdapter(cmd);


DataSet ds = newDataSet();
da.Fill(ds); GridView1.DataSource = ds; GridView1.DataBind();

con.Close();

}
Result

You might also like