Hi
i have 1 Dropdown having list Of Locations . On the basis of selection of Location i want to display in another dropdown list of Offices of that Location from CSV file.
Thanks
i have 1 Dropdown having list Of Locations . On the basis of selection of Location i want to display in another dropdown list of Offices of that Location from CSV file.
Thanks
Jagjit SainiPosted Sep 23, 2011, 2:16 AM
I don't want to use Asp.Net . I want only HTML , Jquery , XML.
Thanks
Hemant KumarPosted Sep 23, 2011, 2:03 AM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
using System.Data;
public partial class FillDropDownListUsingCSV : System.Web.UI.Page
{
string fileName = "President.csv";
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) return;
OleDbConnection connCSV = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/") + ";Extended Properties='text;HDR=Yes;FMT=Delimited(,)';");
string cmdCols = string.Format("SELECT * FROM {0}", fileName);
connCSV.Open();
DataSet ds = new DataSet();
OleDbDataAdapter oda = new OleDbDataAdapter(cmdCols, connCSV);
oda.Fill(ds);
ddlPresident.DataSource = ds;
ddlPresident.DataValueField = "Presidency ";
ddlPresident.DataTextField = "President ";
ddlPresident.DataBind();
ddlPresident.Items.Insert(0, new ListItem { Value = "-1", Text = "" });
connCSV.Close();
}
protected void ddlPresident_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlPresident.SelectedIndex != -1)
{
string cmdCols = String.Empty;
OleDbConnection connCSV = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("App_Data/") + ";Extended Properties='text;HDR=Yes;FMT=Delimited(,)';");
if (!String.IsNullOrEmpty(ddlPresident.SelectedItem.Text))
{
cmdCols = string.Format("SELECT party FROM {0} where president='{1}'", fileName, ddlPresident.SelectedItem.Text);
}
connCSV.Open();
DataSet ds = new DataSet();
OleDbDataAdapter oda = new OleDbDataAdapter(cmdCols, connCSV);
oda.Fill(ds);
ddlParty.DataSource = ds;
ddlParty.DataTextField = "Party";
ddlParty.DataBind();
connCSV.Close();
}
}
}