如何在gridview中保留DropDownList的值
我目前正在做一个为中小型公司开具发票的项目 我有3个下拉列表(DDL) 第一个下拉列表(产品类别)已设置为4个列表项,即地毯、家具等 从第一个DDL中选择后,第二个dropdownlist(产品类型)将从数据库中检索与第一个DDL中所选值匹配的数据 类似地,在从第二个DDL中选择时,第三个dropdownlist(产品ID)将从数据库中检索与第二个DDL中选择的值相匹配的数据 第三,从第三个DDL中选择后,文本框(产品描述、单价)将填充从数据库检索的数据,这些数据与第三个DDL中选择的值相匹配 现在,问题是当我单击“添加新行”按钮时,每次单击该按钮都会动态添加新行,第二个和第三个DDL中的选定值不再存在,但textboxs中的值仍然存在 有人可以帮助我如何保留第二个和第三个DDL的值,即使用户按自己的意愿单击“添加新行”按钮 下面是我到目前为止所做的全部代码 GenInvoice.aspx如何在gridview中保留DropDownList的值,gridview,drop-down-menu,retain,selectedvalue,Gridview,Drop Down Menu,Retain,Selectedvalue,我目前正在做一个为中小型公司开具发票的项目 我有3个下拉列表(DDL) 第一个下拉列表(产品类别)已设置为4个列表项,即地毯、家具等 从第一个DDL中选择后,第二个dropdownlist(产品类型)将从数据库中检索与第一个DDL中所选值匹配的数据 类似地,在从第二个DDL中选择时,第三个dropdownlist(产品ID)将从数据库中检索与第二个DDL中选择的值相匹配的数据 第三,从第三个DDL中选择后,文本框(产品描述、单价)将填充从数据库检索的数据,这些数据与第三个DDL中选择的值相匹配
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage/AdminLogin.master" AutoEventWireup="true" CodeFile="GenInvoice.aspx.cs" Inherits="GenInvoice" %>
请选择
地毯
电机
家具
其他
请选择
请选择
总计:
GenInvoice.aspx.cs
public partial class GenInvoice : System.Web.UI.Page
{
private double subTotal = 0;
protected void Page_Load(object sender, EventArgs e)
{
//GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
if (!Page.IsPostBack)
{
SetInitialRow();
}
}
private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
//dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Row Number", typeof(string)));
dt.Columns.Add(new DataColumn("Category", typeof(string)));
dt.Columns.Add(new DataColumn("Type", typeof(string)));
dt.Columns.Add(new DataColumn("Model No", typeof(string)));
dt.Columns.Add(new DataColumn("Description", typeof(string)));
dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
dt.Columns.Add(new DataColumn("Unit Price", typeof(string)));
dt.Columns.Add(new DataColumn("Sub-Total", typeof(string)));
dr = dt.NewRow();
dr["Row Number"] = 1;
dr["Category"] = string.Empty;
dr["Type"] = string.Empty;
dr["Model No"] = string.Empty;
dr["Description"] = string.Empty;
dr["Quantity"] = string.Empty;
dr["Unit Price"] = string.Empty;
dr["Sub-Total"] = string.Empty;
dt.Rows.Add(dr);
dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}
private void AddNewRowToGrid()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
//extract the TextBox values
//TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
//TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
//DropDownList ddlProductType = (DropDownList)Gridview1.Rows[rowIndex].Cells[2].FindControl("ddlProductType");
DropDownList ddlCategory = (DropDownList)GridView1.Rows[rowIndex].Cells[1].FindControl("ddlCategory");
DropDownList ddlType = (DropDownList)GridView1.Rows[rowIndex].Cells[2].FindControl("ddlType");
DropDownList ddlModelNo = (DropDownList)GridView1.Rows[rowIndex].Cells[3].FindControl("ddlModelNo");
Label lblDescription = (Label)GridView1.Rows[rowIndex].Cells[4].FindControl("lblDescription");
TextBox txtQuantity = (TextBox)GridView1.Rows[rowIndex].Cells[5].FindControl("txtQuantity");
TextBox txtUPrice = (TextBox)GridView1.Rows[rowIndex].Cells[6].FindControl("txtUPrice");
TextBox txtSTotal = (TextBox)GridView1.Rows[rowIndex].Cells[7].FindControl("txtSTotal");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["Row Number"] = i + 1;
//dtCurrentTable.Rows[i - 1]["Category"] = box1.Text;
dtCurrentTable.Rows[i - 1]["Category"] = ddlCategory.Text;
dtCurrentTable.Rows[i - 1]["Type"] = ddlType.Text;
dtCurrentTable.Rows[i - 1]["Model No"] = ddlModelNo.Text;
dtCurrentTable.Rows[i - 1]["Description"] = lblDescription.Text;
dtCurrentTable.Rows[i - 1]["Quantity"] = txtQuantity.Text;
dtCurrentTable.Rows[i - 1]["Unit Price"] = txtUPrice.Text;
dtCurrentTable.Rows[i - 1]["Sub-Total"] = txtSTotal.Text;
rowIndex++;
}
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState["CurrentTable"] = dtCurrentTable;
GridView1.DataSource = dtCurrentTable;
GridView1.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData();
}
private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
//TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
//TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
//DropDownList ddlProductType = (DropDownList)Gridview1.Rows[rowIndex].Cells[2].FindControl("ddlProductType");
DropDownList ddlCategory = (DropDownList)GridView1.Rows[rowIndex].Cells[1].FindControl("ddlCategory");
DropDownList ddlType = (DropDownList)GridView1.Rows[rowIndex].Cells[2].FindControl("ddlType");
DropDownList ddlModelNo = (DropDownList)GridView1.Rows[rowIndex].Cells[3].FindControl("ddlModelNo");
Label lblDescription = (Label)GridView1.Rows[rowIndex].Cells[4].FindControl("lblDescription");
TextBox txtQuantity = (TextBox)GridView1.Rows[rowIndex].Cells[5].FindControl("txtQuantity");
TextBox txtUPrice = (TextBox)GridView1.Rows[rowIndex].Cells[6].FindControl("txtUPrice");
TextBox txtSTotal = (TextBox)GridView1.Rows[rowIndex].Cells[7].FindControl("txtSTotal");
ddlCategory.Text = dt.Rows[i]["Category"].ToString();
ddlType.Text = dt.Rows[i]["Type"].ToString();
ddlModelNo.Text = dt.Rows[i]["Model No"].ToString();
lblDescription.Text = dt.Rows[i]["Description"].ToString();
txtQuantity.Text = dt.Rows[i]["Quantity"].ToString();
txtUPrice.Text = dt.Rows[i]["Unit Price"].ToString();
txtSTotal.Text = dt.Rows[i]["Sub-Total"].ToString();
rowIndex++;
}
}
}
}
protected void btnAddNewRow_Click(object sender, EventArgs e)
{
AddNewRowToGrid();
}
private void Calc()
{
double grandtotal = 0.0;
foreach (GridViewRow dr in GridView1.Rows)
{
double price = Convert.ToDouble(((TextBox)dr.FindControl("txtUPrice")).Text);
//double price = double.Parse(((TextBox)dr.FindControl("txtUPrice")).Text);
int qty = int.Parse(((TextBox)dr.FindControl("txtQuantity")).Text);
//Calculates Sub-Total
double total = price * qty;
//Displays Sub-Total
((TextBox)dr.FindControl("txtSTotal")).Text = Convert.ToString(total);
//Calculates GrandTotal
grandtotal = grandtotal + total;
}
//Displays Grand Total
GridViewRow row = GridView1.FooterRow;
((TextBox)row.FindControl("txtGTotal")).Text = Convert.ToString(grandtotal);
}
protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow dr in GridView1.Rows)
{
//string type = Convert.ToString(((DropDownList)dr.FindControl("ddlType")).Text);
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
DropDownList ddlModelNo = (DropDownList)dr.FindControl("ddlModelNo");
//ddlModelNo.Items.Clear();
//if (type == "Cupboard")
//{
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
//MySqlCommand cmd = new MySqlCommand("SELECT productID FROM product WHERE productType='" + typeCupboard + "'", con);
MySqlCommand cmd2 = new MySqlCommand("SELECT productID FROM product WHERE productType='" + ddlType.SelectedValue + "'", con);
MySqlDataAdapter da1 = new MySqlDataAdapter(cmd2);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
ddlModelNo.DataSource = ds1;
ddlModelNo.DataValueField = "productID";
ddlModelNo.DataTextField = "productID";
ddlModelNo.DataBind();
ddlModelNo.Items.Insert(0, new ListItem("Please Select", "Please Select"));
Session["ddlTypeValue"] = ddlType.SelectedValue;
}
}
protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow dr in GridView1.Rows)
{
//string type = Convert.ToString(((DropDownList)dr.FindControl("ddlType")).Text);
DropDownList ddlCat = (DropDownList)dr.FindControl("ddlCategory");
//DropDownList ddlModelNo = (DropDownList)dr.FindControl("ddlModelNo");
Session["ddlCat"] = ddlCat.SelectedValue;
string category = Convert.ToString(((DropDownList)dr.FindControl("ddlCategory")).Text);
if (category == "Carpets")
{
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT carpets FROM producttypecarpets", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
//MySqlDataReader dz = cmd.ExecuteReader();
DataSet ds = new DataSet();
da.Fill(ds);
ddlType.DataSource = ds;
ddlType.DataValueField = "carpets";
ddlType.DataTextField = "carpets";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("Please Select", "Please Select"));
}
if (category == "Electrical Appliances")
{
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT electrical FROM producttypeelectrical", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
//MySqlDataReader dz = cmd.ExecuteReader();
DataSet ds = new DataSet();
da.Fill(ds);
ddlType.DataSource = ds;
ddlType.DataValueField = "electrical";
ddlType.DataTextField = "electrical";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("Please Select", "Please Select"));
}
if (category == "Furnitures")
{
DropDownList ddlCategory = (DropDownList)dr.FindControl("ddlCategory");
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
//DropDownList ddlModelNo = (DropDownList)dr.FindControl("ddlModelNo");
//Label lblDescription = (Label)dr.FindControl("lblDescription");
//TextBox txtUPrice = (TextBox)dr.FindControl("txtUPrice");
//string catFurnitures = "Furnitures";
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT DISTINCT productType FROM product WHERE productCategory='" + ddlCategory.SelectedValue + "'", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
//MySqlDataReader dz = cmd.ExecuteReader();
DataSet ds = new DataSet();
da.Fill(ds);
ddlType.DataSource = ds;
ddlType.DataValueField = "productType";
ddlType.DataTextField = "productType";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("Please Select", "Please Select"));
}
//if (category == "Others")
//Type();
//GridView1.DataBind();
}
}
protected void ddlModelNo_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow dr in GridView1.Rows)
{
string type = Convert.ToString(((DropDownList)dr.FindControl("ddlType")).Text);
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
DropDownList ddlModelNo = (DropDownList)dr.FindControl("ddlModelNo");
Label lblDescription = (Label)dr.FindControl("lblDescription");
TextBox txtUPrice = (TextBox)dr.FindControl("txtUPrice");
//if (type == "Cupboard")
//{
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
//MySqlCommand cmd = new MySqlCommand("SELECT productID FROM product WHERE productType='" + typeCupboard + "'", con);
MySqlCommand cmd2 = new MySqlCommand("SELECT productDesc,productSellingPrice FROM product WHERE productID='" + ddlModelNo.SelectedValue + "'", con);
MySqlDataAdapter da1 = new MySqlDataAdapter(cmd2);
MySqlDataReader myDataReader = cmd2.ExecuteReader();
while (myDataReader.Read())
{
//ddlCompanyName.Items.Add(dr["compName"].ToString());
lblDescription.Text = myDataReader["productDesc"].ToString();
txtUPrice.Text = myDataReader["productSellingPrice"].ToString();
}
DataSet ds1 = new DataSet();
da1.Fill(ds1);
ddlModelNo.DataSource = ds1;
ddlModelNo.DataValueField = "productID";
ddlModelNo.DataTextField = "productID";
ddlModelNo.DataBind();
}
}
protected void txtQuantity_TextChanged(object sender, EventArgs e)
{
Calc();
}
}
公共部分类GenInvoice:System.Web.UI.Page
{
私人双倍小计=0;
受保护的无效页面加载(对象发送方、事件参数e)
{
//GridView1.RowDataBound+=新的GridViewRowEventHandler(GridView1_RowDataBound);
如果(!Page.IsPostBack)
{
SetInitialRow();
}
}
私有void SetInitialRow()
{
DataTable dt=新的DataTable();
数据行dr=null;
//添加(新的数据列(“行数”,typeof(字符串));
添加(新的数据列(“行号”,typeof(字符串));
添加(新的数据列(“类别”,类型(字符串));
添加(新的数据列(“Type”,typeof(string));
添加(新数据列(“型号”,类型(字符串));
添加(新的数据列(“说明”,类型(字符串));
添加(新数据列(“数量”,类型(字符串));
添加(新数据列(“单价”,类型为(字符串));
添加(新数据列(“小计”,类型为(字符串));
dr=dt.NewRow();
dr[“行号”]=1;
dr[“Category”]=string.Empty;
dr[“Type”]=string.Empty;
dr[“型号”]=字符串。空;
dr[“Description”]=string.Empty;
dr[“数量”]=字符串。空;
dr[“单价”]=字符串。空;
dr[“小计”]=字符串。为空;
dt.Rows.Add(dr);
dr=dt.NewRow();
//将数据表存储在ViewState中
视图状态[“当前表”]=dt;
GridView1.DataSource=dt;
GridView1.DataBind();
}
私有void AddNewRowToGrid()
{
int rowIndex=0;
如果(ViewState[“CurrentTable”]!=null)
{
DataTable dtCurrentTable=(DataTable)视图状态[“CurrentTable”];
DataRow drCurrentRow=null;
如果(dtCurrentTable.Rows.Count>0)
{
对于(int i=1;i 0)
{
对于(int i=0;ipublic partial class GenInvoice : System.Web.UI.Page
{
private double subTotal = 0;
protected void Page_Load(object sender, EventArgs e)
{
//GridView1.RowDataBound += new GridViewRowEventHandler(GridView1_RowDataBound);
if (!Page.IsPostBack)
{
SetInitialRow();
}
}
private void SetInitialRow()
{
DataTable dt = new DataTable();
DataRow dr = null;
//dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
dt.Columns.Add(new DataColumn("Row Number", typeof(string)));
dt.Columns.Add(new DataColumn("Category", typeof(string)));
dt.Columns.Add(new DataColumn("Type", typeof(string)));
dt.Columns.Add(new DataColumn("Model No", typeof(string)));
dt.Columns.Add(new DataColumn("Description", typeof(string)));
dt.Columns.Add(new DataColumn("Quantity", typeof(string)));
dt.Columns.Add(new DataColumn("Unit Price", typeof(string)));
dt.Columns.Add(new DataColumn("Sub-Total", typeof(string)));
dr = dt.NewRow();
dr["Row Number"] = 1;
dr["Category"] = string.Empty;
dr["Type"] = string.Empty;
dr["Model No"] = string.Empty;
dr["Description"] = string.Empty;
dr["Quantity"] = string.Empty;
dr["Unit Price"] = string.Empty;
dr["Sub-Total"] = string.Empty;
dt.Rows.Add(dr);
dr = dt.NewRow();
//Store the DataTable in ViewState
ViewState["CurrentTable"] = dt;
GridView1.DataSource = dt;
GridView1.DataBind();
}
private void AddNewRowToGrid()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dtCurrentTable = (DataTable)ViewState["CurrentTable"];
DataRow drCurrentRow = null;
if (dtCurrentTable.Rows.Count > 0)
{
for (int i = 1; i <= dtCurrentTable.Rows.Count; i++)
{
//extract the TextBox values
//TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
//TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
//DropDownList ddlProductType = (DropDownList)Gridview1.Rows[rowIndex].Cells[2].FindControl("ddlProductType");
DropDownList ddlCategory = (DropDownList)GridView1.Rows[rowIndex].Cells[1].FindControl("ddlCategory");
DropDownList ddlType = (DropDownList)GridView1.Rows[rowIndex].Cells[2].FindControl("ddlType");
DropDownList ddlModelNo = (DropDownList)GridView1.Rows[rowIndex].Cells[3].FindControl("ddlModelNo");
Label lblDescription = (Label)GridView1.Rows[rowIndex].Cells[4].FindControl("lblDescription");
TextBox txtQuantity = (TextBox)GridView1.Rows[rowIndex].Cells[5].FindControl("txtQuantity");
TextBox txtUPrice = (TextBox)GridView1.Rows[rowIndex].Cells[6].FindControl("txtUPrice");
TextBox txtSTotal = (TextBox)GridView1.Rows[rowIndex].Cells[7].FindControl("txtSTotal");
drCurrentRow = dtCurrentTable.NewRow();
drCurrentRow["Row Number"] = i + 1;
//dtCurrentTable.Rows[i - 1]["Category"] = box1.Text;
dtCurrentTable.Rows[i - 1]["Category"] = ddlCategory.Text;
dtCurrentTable.Rows[i - 1]["Type"] = ddlType.Text;
dtCurrentTable.Rows[i - 1]["Model No"] = ddlModelNo.Text;
dtCurrentTable.Rows[i - 1]["Description"] = lblDescription.Text;
dtCurrentTable.Rows[i - 1]["Quantity"] = txtQuantity.Text;
dtCurrentTable.Rows[i - 1]["Unit Price"] = txtUPrice.Text;
dtCurrentTable.Rows[i - 1]["Sub-Total"] = txtSTotal.Text;
rowIndex++;
}
dtCurrentTable.Rows.Add(drCurrentRow);
ViewState["CurrentTable"] = dtCurrentTable;
GridView1.DataSource = dtCurrentTable;
GridView1.DataBind();
}
}
else
{
Response.Write("ViewState is null");
}
//Set Previous Data on Postbacks
SetPreviousData();
}
private void SetPreviousData()
{
int rowIndex = 0;
if (ViewState["CurrentTable"] != null)
{
DataTable dt = (DataTable)ViewState["CurrentTable"];
if (dt.Rows.Count > 0)
{
for (int i = 0; i < dt.Rows.Count; i++)
{
//TextBox box1 = (TextBox)Gridview1.Rows[rowIndex].Cells[1].FindControl("TextBox1");
//TextBox box2 = (TextBox)Gridview1.Rows[rowIndex].Cells[2].FindControl("TextBox2");
//DropDownList ddlProductType = (DropDownList)Gridview1.Rows[rowIndex].Cells[2].FindControl("ddlProductType");
DropDownList ddlCategory = (DropDownList)GridView1.Rows[rowIndex].Cells[1].FindControl("ddlCategory");
DropDownList ddlType = (DropDownList)GridView1.Rows[rowIndex].Cells[2].FindControl("ddlType");
DropDownList ddlModelNo = (DropDownList)GridView1.Rows[rowIndex].Cells[3].FindControl("ddlModelNo");
Label lblDescription = (Label)GridView1.Rows[rowIndex].Cells[4].FindControl("lblDescription");
TextBox txtQuantity = (TextBox)GridView1.Rows[rowIndex].Cells[5].FindControl("txtQuantity");
TextBox txtUPrice = (TextBox)GridView1.Rows[rowIndex].Cells[6].FindControl("txtUPrice");
TextBox txtSTotal = (TextBox)GridView1.Rows[rowIndex].Cells[7].FindControl("txtSTotal");
ddlCategory.Text = dt.Rows[i]["Category"].ToString();
ddlType.Text = dt.Rows[i]["Type"].ToString();
ddlModelNo.Text = dt.Rows[i]["Model No"].ToString();
lblDescription.Text = dt.Rows[i]["Description"].ToString();
txtQuantity.Text = dt.Rows[i]["Quantity"].ToString();
txtUPrice.Text = dt.Rows[i]["Unit Price"].ToString();
txtSTotal.Text = dt.Rows[i]["Sub-Total"].ToString();
rowIndex++;
}
}
}
}
protected void btnAddNewRow_Click(object sender, EventArgs e)
{
AddNewRowToGrid();
}
private void Calc()
{
double grandtotal = 0.0;
foreach (GridViewRow dr in GridView1.Rows)
{
double price = Convert.ToDouble(((TextBox)dr.FindControl("txtUPrice")).Text);
//double price = double.Parse(((TextBox)dr.FindControl("txtUPrice")).Text);
int qty = int.Parse(((TextBox)dr.FindControl("txtQuantity")).Text);
//Calculates Sub-Total
double total = price * qty;
//Displays Sub-Total
((TextBox)dr.FindControl("txtSTotal")).Text = Convert.ToString(total);
//Calculates GrandTotal
grandtotal = grandtotal + total;
}
//Displays Grand Total
GridViewRow row = GridView1.FooterRow;
((TextBox)row.FindControl("txtGTotal")).Text = Convert.ToString(grandtotal);
}
protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow dr in GridView1.Rows)
{
//string type = Convert.ToString(((DropDownList)dr.FindControl("ddlType")).Text);
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
DropDownList ddlModelNo = (DropDownList)dr.FindControl("ddlModelNo");
//ddlModelNo.Items.Clear();
//if (type == "Cupboard")
//{
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
//MySqlCommand cmd = new MySqlCommand("SELECT productID FROM product WHERE productType='" + typeCupboard + "'", con);
MySqlCommand cmd2 = new MySqlCommand("SELECT productID FROM product WHERE productType='" + ddlType.SelectedValue + "'", con);
MySqlDataAdapter da1 = new MySqlDataAdapter(cmd2);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
ddlModelNo.DataSource = ds1;
ddlModelNo.DataValueField = "productID";
ddlModelNo.DataTextField = "productID";
ddlModelNo.DataBind();
ddlModelNo.Items.Insert(0, new ListItem("Please Select", "Please Select"));
Session["ddlTypeValue"] = ddlType.SelectedValue;
}
}
protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow dr in GridView1.Rows)
{
//string type = Convert.ToString(((DropDownList)dr.FindControl("ddlType")).Text);
DropDownList ddlCat = (DropDownList)dr.FindControl("ddlCategory");
//DropDownList ddlModelNo = (DropDownList)dr.FindControl("ddlModelNo");
Session["ddlCat"] = ddlCat.SelectedValue;
string category = Convert.ToString(((DropDownList)dr.FindControl("ddlCategory")).Text);
if (category == "Carpets")
{
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT carpets FROM producttypecarpets", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
//MySqlDataReader dz = cmd.ExecuteReader();
DataSet ds = new DataSet();
da.Fill(ds);
ddlType.DataSource = ds;
ddlType.DataValueField = "carpets";
ddlType.DataTextField = "carpets";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("Please Select", "Please Select"));
}
if (category == "Electrical Appliances")
{
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT electrical FROM producttypeelectrical", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
//MySqlDataReader dz = cmd.ExecuteReader();
DataSet ds = new DataSet();
da.Fill(ds);
ddlType.DataSource = ds;
ddlType.DataValueField = "electrical";
ddlType.DataTextField = "electrical";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("Please Select", "Please Select"));
}
if (category == "Furnitures")
{
DropDownList ddlCategory = (DropDownList)dr.FindControl("ddlCategory");
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
//DropDownList ddlModelNo = (DropDownList)dr.FindControl("ddlModelNo");
//Label lblDescription = (Label)dr.FindControl("lblDescription");
//TextBox txtUPrice = (TextBox)dr.FindControl("txtUPrice");
//string catFurnitures = "Furnitures";
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
MySqlCommand cmd = new MySqlCommand("SELECT DISTINCT productType FROM product WHERE productCategory='" + ddlCategory.SelectedValue + "'", con);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
//MySqlDataReader dz = cmd.ExecuteReader();
DataSet ds = new DataSet();
da.Fill(ds);
ddlType.DataSource = ds;
ddlType.DataValueField = "productType";
ddlType.DataTextField = "productType";
ddlType.DataBind();
ddlType.Items.Insert(0, new ListItem("Please Select", "Please Select"));
}
//if (category == "Others")
//Type();
//GridView1.DataBind();
}
}
protected void ddlModelNo_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow dr in GridView1.Rows)
{
string type = Convert.ToString(((DropDownList)dr.FindControl("ddlType")).Text);
DropDownList ddlType = (DropDownList)dr.FindControl("ddlType");
DropDownList ddlModelNo = (DropDownList)dr.FindControl("ddlModelNo");
Label lblDescription = (Label)dr.FindControl("lblDescription");
TextBox txtUPrice = (TextBox)dr.FindControl("txtUPrice");
//if (type == "Cupboard")
//{
MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=;database=obsystem");
con.Open();
//MySqlCommand cmd = new MySqlCommand("SELECT productID FROM product WHERE productType='" + typeCupboard + "'", con);
MySqlCommand cmd2 = new MySqlCommand("SELECT productDesc,productSellingPrice FROM product WHERE productID='" + ddlModelNo.SelectedValue + "'", con);
MySqlDataAdapter da1 = new MySqlDataAdapter(cmd2);
MySqlDataReader myDataReader = cmd2.ExecuteReader();
while (myDataReader.Read())
{
//ddlCompanyName.Items.Add(dr["compName"].ToString());
lblDescription.Text = myDataReader["productDesc"].ToString();
txtUPrice.Text = myDataReader["productSellingPrice"].ToString();
}
DataSet ds1 = new DataSet();
da1.Fill(ds1);
ddlModelNo.DataSource = ds1;
ddlModelNo.DataValueField = "productID";
ddlModelNo.DataTextField = "productID";
ddlModelNo.DataBind();
}
}
protected void txtQuantity_TextChanged(object sender, EventArgs e)
{
Calc();
}
}
ddlCategory.Text = dt.Rows[i]["Category"].ToString();
ddlType.Text = dt.Rows[i]["Type"].ToString();
ddlModelNo.Text = dt.Rows[i]["Model No"].ToString();
fillCategory();
if(ddlCategory.items.contains(ddlCategory.items.FindByText(dt.Rows[i]["Category"].ToString())))
{
ddlCategory.clearselection();
ddlCategory.items.FindByText(dt.Rows[i]["Category"].ToString()).Selected=True;
}
fillType();
if(ddlType.items.contains(ddlType.items.FindByText(dt.Rows[i]["Type"].ToString())))
{
ddlType.clearselection();
ddlType.items.FindByText(dt.Rows[i]["Type"].ToString()).Selected=True;
}
fillModel();
if(ddlModelNo.items.contains(ddlModelNo.items.FindByText(dt.Rows[i]["Model No"].ToString())))
{
ddlModelNo.clearselection();
ddlModelNo.items.FindByText(dt.Rows[i]["Model No"].ToString()).Selected=True;
}