//Connection String
//Page Load Code here
SqlConnection(ConfigurationManager.ConnectionStrings["Master1"].ConnectionString);
SqlCommand cmd;
SqlDataAdapter adp;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
con.Open();
cmd = new SqlCommand("Select category_id,category_name from tbl_category order by category_id", con);
adp = new SqlDataAdapter(cmd);
ds = new DataSet();
adp.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
drpCategory1.Items.Add(ds.Tables[0].Rows[i]["Category_Name"].ToString());
drpCategory1.Items[i + 1].Value = ds.Tables[0].Rows[i]["Category_id"].ToString();
}
}
ds.Dispose();
adp=null;
con.Close();
}
}
No comments:
Post a Comment