protected void GVPro_RowDataBound(object sender, GridViewRowEventArgs e) { try { //Item Type dt_ = new DataTable(); dt_ = DBConnection.GetQueryData("select rtrim('[' + CAST(ProductTypeID AS VARCHAR(200)) + ']-' + ProductTypeName ) as [ProductTypeName], ProductTypeID from tbl_producttype where IsActive = 1 "); for (int i = 0; i < GVPro.Rows.Count; i++) { DropDownList DDL_Itmtyp = (DropDownList)GVPro.Rows[i].Cells[0].FindControl("DDL_Itmtyp"); DDL_Itmtyp.DataSource = dt_; DDL_Itmtyp.DataTextField = "ProductTypeName"; DDL_Itmtyp.DataValueField = "ProductTypeID"; DDL_Itmtyp.DataBind(); DDL_Itmtyp.Items.Insert(0, new ListItem("--Select Items Types--", "0")); } //Item Name dt_ = new DataTable(); dt_ = DBConnection.GetQueryData("select rtrim('[' + CAST(ProductID AS VARCHAR(200)) + ']-' + ProductName ) as [ProductName], ProductID from Products"); DDL_Itm.DataSource = dt_; DDL_Itm.DataTextField = "ProductName"; DDL_Itm.DataValueField = "ProductID"; DDL_Itm.DataBind(); DDL_Itm.Items.Insert(0, new ListItem("--Select Items --", "0")); } catch (Exception ex) { throw ex; } }
public void BindDDL() { try { //Units dt_ = new DataTable(); dt_ = DBConnection.GetQueryData("select rtrim('[' + CAST(untid AS VARCHAR(200)) + ']-' + untnam ) as [untnam], untid from tbl_unts where CompanyId = '" + Session["CompanyID"] + "' and BranchId= '" + Session["BranchID"] + "'"); for (int i = 0; i < GVPro.Rows.Count; i++) { DropDownList DDL_Unt = (DropDownList)GVPro.Rows[i].Cells[0].FindControl("DDL_Unt"); DDL_Unt.DataSource = dt_; DDL_Unt.DataTextField = "untnam"; DDL_Unt.DataValueField = "untid"; DDL_Unt.DataBind(); DDL_Unt.Items.Insert(0, new ListItem("--Select Units--", "0")); } //Item Type dt_ = new DataTable(); //dt_ = DBConnection.GetQueryData("select rtrim('[' + CAST(ProductTypeID AS VARCHAR(200)) + ']-' + ProductTypeName ) as [ProductTypeName], ProductTypeID from tbl_producttype"); dt_ = DBConnection.GetQueryData("select * from tbl_producttype where CompanyId = '" + Session["CompanyID"] + "' and BranchId= '" + Session["BranchID"] + "'"); for (int i = 0; i < GVPro.Rows.Count; i++) { DropDownList DDL_Itmtyp = (DropDownList)GVPro.Rows[i].Cells[0].FindControl("DDL_Itmtyp"); DDL_Itmtyp.DataSource = dt_; DDL_Itmtyp.DataTextField = "ProductTypeName"; DDL_Itmtyp.DataValueField = "ProductTypeID"; DDL_Itmtyp.DataBind(); DDL_Itmtyp.Items.Insert(0, new ListItem("--Select Items Types--", "0")); } //Item Name dt_ = new DataTable(); dt_ = DBConnection.GetQueryData("select rtrim('[' + CAST(ProductID AS VARCHAR(200)) + ']-' + ProductName ) as [ProductName], ProductID from Products where CompanyId = '" + Session["CompanyID"] + "' and BranchId= '" + Session["BranchID"] + "'"); DDL_Itm.DataSource = dt_; DDL_Itm.DataTextField = "ProductName"; DDL_Itm.DataValueField = "ProductID"; DDL_Itm.DataBind(); DDL_Itm.Items.Insert(0, new ListItem("--Select Items --", "0")); //using (SqlCommand cmdpar = new SqlCommand()) //{ // //con.Close(); // //cmdpar.CommandText = " select rtrim('[' + CAST(SubHeadCategoriesGeneratedID AS VARCHAR(200)) + ']-' + SubHeadCategoriesName ) as [SubHeadCategoriesName], SubHeadCategoriesID from SubHeadCategories "; // cmdpar.CommandText = " "; // cmdpar.Connection = con; // con.Open(); // DataTable dtpar = new DataTable(); // SqlDataAdapter adp = new SqlDataAdapter(cmdpar); // adp.Fill(dtpar); // con.Close(); //} //using (SqlCommand cmdItmnam = new SqlCommand()) //{ // con.Close(); // //cmdpar.CommandText = " "; // cmdItmnam.CommandText = " "; // cmdItmnam.Connection = con; // con.Open(); // DataTable dtItmnam = new DataTable(); // SqlDataAdapter adpItmnam = new SqlDataAdapter(cmdItmnam); // adpItmnam.Fill(dtItmnam); // for (int i = 0; i < GVPro.Rows.Count; i++) // { // DropDownList DDL_Itmtyp = (DropDownList)GVPro.Rows[i].Cells[0].FindControl("DDL_Itmtyp"); // DDL_Itmtyp.DataSource = dtItmnam; // DDL_Itmtyp.DataTextField = ""; // DDL_Itmtyp.DataValueField = ""; // DDL_Itmtyp.DataBind(); // DDL_Itmtyp.Items.Insert(0, new ListItem("--Select Items Types--", "0")); // } // con.Close(); //} } catch (Exception ex) { ScriptManager.RegisterStartupScript(this, this.GetType(), "isActive", "Alert();", true); lblalert.Text = ex.Message; } }