Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Post
Register
Login
0
Reply
Why this code Write down in Page_Load ?
Palash Kayal
Sep 12 2017 6:30 AM
122
Reply
protected
void
Page_Load(
object
sender, EventArgs e)
{
// Why this code Load in Page_Load
if
(!Page.IsPostBack)
{
SqlConnection con =
new
SqlConnection(@
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
);
SqlCommand cmd =
new
SqlCommand(
"select * from tbl_country"
, con);
SqlDataAdapter sda =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
sda.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataBind();
}
// end Why this code Load in Page_Load
}
protected
void
DropDownList1_SelectedIndexChanged(
object
sender, EventArgs e)
{
DropDownList2.Items.Clear();
DropDownList2.Items.Add(
"Select State"
);
SqlConnection con =
new
SqlConnection(@
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
);
SqlCommand cmd =
new
SqlCommand(
"select * from tbl_state where country_id="
+ DropDownList1.SelectedItem.Value, con);
SqlDataAdapter sda =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
sda.Fill(dt);
DropDownList2.DataSource= dt;
DropDownList2.DataBind();
}
protected
void
DropDownList2_SelectedIndexChanged(
object
sender, EventArgs e)
{
DropDownList3.Items.Clear();
DropDownList3.Items.Add(
"Select State"
);
SqlConnection con =
new
SqlConnection(@
"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True"
);
SqlCommand cmd =
new
SqlCommand(
"select * from tbl_city where state_id="
+ DropDownList2.SelectedItem.Value, con);
SqlDataAdapter sda =
new
SqlDataAdapter(cmd);
DataTable dt =
new
DataTable();
sda.Fill(dt);
DropDownList3.DataSource = dt;
DropDownList3.DataBind();
}
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
How to read data from datatable in C#
varchar datatype to date conversion in select query