TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Palash Kayal
NA
5
1.2k
Why this code Write down in Page_Load ?
Sep 12 2017 6:30 AM
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();
}
Reply
Answers (
0
)
How to read data from datatable in C#
varchar datatype to date conversion in select query