I've bound three drop down lists with same oledb data adapter. this oledbdataadapter fills three different datatables which I use eventually to fill up three dropdowns. But when I access three dropdown values in submit button, all three dropdowns give same selected item even when I've selected three different options in dropdowns. Can Anybody help?
here's my code:-
cmdExcel.CommandText = "Select * from [" + SheetName + "]";
oda.SelectCommand = cmdExcel;
oda.Fill(dt_Temp);
DataTable dt_costcode = new DataTable();
oda.Fill(dt_costcode);
DataTable dt_desc = new DataTable();
oda.Fill(dt_desc);
DataTable dt_unit = new DataTable();
oda.Fill(dt_unit);
connExcel.Close();
ViewState["TempImport"] = dt_Temp;
List<CostColumns> list_costCode = Columns(dt_costcode);
Bind_ddlCostCode(list_costCode);
List<CostColumns> list_desc = Columns(dt_desc);
Bind_ddlDescription(list_desc);
List<CostColumns> list_unit = Columns(dt_unit);
Bind_ddlUnitofMeasure(list_unit);
here code for binding Dropdowns:-
<public void Bind_ddlCostCode(List<CostColumns> list_costCode)
{
foreach (CostColumns costcol in list_costCode.ToList())
{
if (costcol.ColumnType == "System.String")
{
ddlCostCodeNumber.Items.Add(new ListItem(costcol.Columns, costcol.ColumnType));
}
}
ddlCostCodeNumber.DataBind();
ddlCostCodeNumber.Items.Insert(0, new ListItem("--Select CostCode--", "0"));
}
public void Bind_ddlDescription(List<CostColumns> list_desc)
{
foreach (CostColumns costcol in list_desc.ToList())
{
if (costcol.ColumnType == "System.String")
{
ddlDescription.Items.Add(new ListItem(costcol.Columns, costcol.ColumnType));
}
}
ddlDescription.DataBind();
ddlDescription.Items.Insert(0, new ListItem("--Select Desc.--", "0"));
}
public List Columns(DataTable dt)
{
List list=new List();
CostColumns CC ;
foreach (DataColumn col in dt.Columns)
{
CC = new CostColumns();
CC.Columns=Convert.ToString(col.ColumnName);
CC.ColumnType=Convert.ToString(col.DataType);
list.Add(CC);
}
return list;
}
And here's where It all goes wrong:-
protected void Btn_ImportRecords_Click(object sender, EventArgs e)
{
DataTable dt_Temp= (DataTable)ViewState["TempImport"];
DataTable dt_Import = new DataTable();
Int32 i = costCodeNo();
string ccn = ddlCostCodeNumber.SelectedItem.Text;
string desc = ddlDescription.SelectedItem.Text;
string unit = ddlUnitofMeasure.SelectedItem.Text;
dt_Import.Columns.Add(new DataColumn("CostCodeNo", typeof(Int32)));
dt_Import.Columns.Add(new DataColumn(ddlCostCodeNumber.SelectedItem.Text, typeof(string)));
dt_Import.Columns.Add(new DataColumn(ddlDescription.SelectedItem.Text, typeof(string)));
}
What I have tried:
I've tried creating diffrent datatables for different dropdowns but so far no luck.