protected void gvGoodsData_SelectedIndexChanged(object sender, EventArgs e) { if (gvEditData.Rows.Count != 0) { AddData dataa = new AddData() { id = "", pm = this.gvGoodsData.SelectedRow.Cells[0].Text.Trim(), spec = this.gvGoodsData.SelectedRow.Cells[2].Text.Trim(), cz = this.gvGoodsData.SelectedRow.Cells[3].Text.Trim(), ys = this.gvGoodsData.SelectedRow.Cells[4].Text.Trim(), goods_unit = this.gvGoodsData.SelectedRow.Cells[5].Text.Trim(), pch = this.gvGoodsData.SelectedRow.Cells[6].Text == " " ? "" : this.gvGoodsData.SelectedRow.Cells[6].Text.Trim(), hwh = this.gvGoodsData.SelectedRow.Cells[7].Text == " " ? "" : this.gvGoodsData.SelectedRow.Cells[7].Text.Trim(), pdsl = this.gvGoodsData.SelectedRow.Cells[8].Text == " " ? "0" : Convert.ToDecimal(this.gvGoodsData.SelectedRow.Cells[8].Text).ToString("0.##"), Price = this.gvGoodsData.SelectedRow.Cells[9].Text == " " ? "0" : Convert.ToDecimal(this.gvGoodsData.SelectedRow.Cells[9].Text).ToString("0.##"), total = "0", customer_name = this.gvGoodsData.SelectedRow.Cells[10].Text.Trim(), }; List <string> sList = getBatch_id(dataa.pm, dataa.pch); InsertCommandBuilder ins = new InsertCommandBuilder("pd_detail"); string Bill_id = ViewState["billId"].ToString(); ins.InsertColumn("Bill_id", Bill_id); ins.InsertColumn("prd_Batch_id", sList[1].Trim()); ins.InsertColumn("materials_id", sList[0].Trim()); ins.InsertColumn("Qty", dataa.pdsl); ins.InsertColumn("Pch", dataa.pch); string detail_id = new SelectCommandBuilder().ExecuteDataTable("SELECT MAX(Detail_id) AS maxId FROM pd_detail where bill_id = '" + Bill_id + "'").Rows[0][0].ToString(); int i = Convert.ToInt32(detail_id.Substring(detail_id.Length - 4, 4)); ins.InsertColumn("Detail_id", Bill_id + (i + 1).ToString().PadLeft(4, '0')); ins.InsertColumn("Price", dataa.Price); ins.InsertColumn("is_can_sale", "Y"); ins.InsertColumn("hwh", dataa.hwh); ins.InsertColumn("is_new", "Y"); ins.getInsertCommand(); ins.ExecuteNonQuery(); //if (aList.Count==0) //{ // btnSelect_Click(sender, e); //} trgoods.Visible = false; AddData data1 = new AddData() { id = Bill_id + (i + 1).ToString().PadLeft(4, '0'), pm = this.gvGoodsData.SelectedRow.Cells[0].Text.Trim(), spec = this.gvGoodsData.SelectedRow.Cells[2].Text.Trim(), cz = this.gvGoodsData.SelectedRow.Cells[3].Text.Trim(), ys = this.gvGoodsData.SelectedRow.Cells[4].Text.Trim(), goods_unit = this.gvGoodsData.SelectedRow.Cells[5].Text.Trim(), pch = this.gvGoodsData.SelectedRow.Cells[6].Text == " " ? "" : this.gvGoodsData.SelectedRow.Cells[6].Text.Trim(), hwh = this.gvGoodsData.SelectedRow.Cells[7].Text == " " ? "" : this.gvGoodsData.SelectedRow.Cells[7].Text.Trim(), pdsl = this.gvGoodsData.SelectedRow.Cells[8].Text == " " ? "0" : Convert.ToDecimal(this.gvGoodsData.SelectedRow.Cells[8].Text).ToString("0.##"), Price = this.gvGoodsData.SelectedRow.Cells[9].Text == " " ? "0" : Convert.ToDecimal(this.gvGoodsData.SelectedRow.Cells[9].Text).ToString("0.##"), total = "0", customer_name = this.gvGoodsData.SelectedRow.Cells[10].Text.Trim(), }; aList.Insert(0, data1); gvAddData.DataSource = aList; gvAddData.DataBind(); return; } AddData data = new AddData() { id = "", pm = this.gvGoodsData.SelectedRow.Cells[0].Text.Trim(), spec = this.gvGoodsData.SelectedRow.Cells[2].Text.Trim(), cz = this.gvGoodsData.SelectedRow.Cells[3].Text.Trim(), ys = this.gvGoodsData.SelectedRow.Cells[4].Text.Trim(), goods_unit = this.gvGoodsData.SelectedRow.Cells[5].Text.Trim(), pch = this.gvGoodsData.SelectedRow.Cells[6].Text == " " ? "" : this.gvGoodsData.SelectedRow.Cells[6].Text.Trim(), hwh = this.gvGoodsData.SelectedRow.Cells[7].Text == " " ? "" : this.gvGoodsData.SelectedRow.Cells[7].Text.Trim(), pdsl = this.gvGoodsData.SelectedRow.Cells[8].Text == " " ? "0" : Convert.ToDecimal(this.gvGoodsData.SelectedRow.Cells[8].Text).ToString("0.##"), Price = this.gvGoodsData.SelectedRow.Cells[9].Text == " " ? "0" : Convert.ToDecimal(this.gvGoodsData.SelectedRow.Cells[9].Text).ToString("0.##"), total = "0", customer_name = this.gvGoodsData.SelectedRow.Cells[10].Text.Trim(), s_id = this.gvGoodsData.SelectedRow.Cells[11].Text.Trim(), b_id = this.gvGoodsData.SelectedRow.Cells[12].Text.Trim() }; lList.Insert(0, data); gvAddData.DataSource = lList; gvAddData.DataBind(); (gvAddData.Rows[0].Cells[7].FindControl("txtpdsl") as TextBox).Attributes.Add("onfocus", "this.select();"); Page.ClientScript.RegisterStartupScript(this.GetType(), "focus", "<script>document.all.gvAddData_ctl02_txtpdsl.focus()</script>"); gvGoodsData.DataSource = null; gvGoodsData.DataBind(); gvAddData.Columns[11].Visible = true; gvAddData.Columns[12].Visible = false; trgoods.Visible = false; }