public void BuildBranches() { DataTable dtBranches = new DataTable(); divBranches.Controls.Clear(); objsupplyPL.username = Session["username"].ToString(); dtBranches = objsupplyBAL.GetHOEnteredBranches(objsupplyPL); if (dtBranches.Rows.Count > 0) { for (int i = 0; i < dtBranches.Rows.Count; i++) { DataTable dtIndentDetails = new DataTable(); string branches=dtBranches.Rows[i]["branch"].ToString(); objsupplyPL.branch = branches; dtIndentDetails = objsupplyBAL.GetStock(objsupplyPL); Table tbldynamic = new Table(); TableRow tr = new TableRow(); TableCell tc = new TableCell(); GridView gv = new GridView(); gv.ID = "gv" + dtBranches.Rows[i]["branch"].ToString(); gv.Width = 500; BoundField bfsno = new BoundField(); bfsno.HeaderText = "S.No"; bfsno.DataField = "sno"; gv.Columns.Add(bfsno); BoundField bfpurchaseid = new BoundField(); bfpurchaseid.HeaderText = "Productid"; bfpurchaseid.DataField = "productid"; gv.Columns.Add(bfpurchaseid); BoundField bfProductId = new BoundField(); bfProductId.HeaderText = "Product Name"; bfProductId.DataField = "productname"; gv.Columns.Add(bfProductId); BoundField bfIssue = new BoundField(); bfIssue.HeaderText = "Issue"; gv.Columns.Add(bfIssue); BoundField bfgrno = new BoundField(); bfgrno.HeaderText = "Transfer"; gv.Columns.Add(bfgrno); gv.DataKeyNames = new string[] { "keys","branch" }; gv.RowDataBound += new GridViewRowEventHandler(gv_RowDataBound); gv.RowCommand += new GridViewCommandEventHandler(gv_RowCommand); gv.AutoGenerateColumns = false; gv.EmptyDataText = "No Records Found"; gv.DataSource = dtIndentDetails; gv.DataBind(); divBranches.Controls.Add(tbldynamic); divBranches.Controls.Add(gv); LiteralControl @break1 = default(LiteralControl); @break1 = new LiteralControl("<br />"); divBranches.Controls.Add(@break1); } } }
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { TemplateField tfLink = new TemplateField(); Button lnk = new Button(); lnk.Text = "Issue"; lnk.CommandName = "issue"; lnk.Click += new EventHandler(MPIssue_Click); e.Row.Cells[4].Controls.Add(lnk); TemplateField tfTransfer = new TemplateField(); Button btnTransfer = new Button(); btnTransfer.Text = "Transfer"; btnTransfer.CommandName = "transfer"; btnTransfer.Click += new EventHandler(MPTransfer_Click); e.Row.Cells[5].Controls.Add(btnTransfer); } }
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.ToUpper() == "ISSUE") { GridViewRow row = (GridViewRow)((Button)e.CommandSource).NamingContainer; lbl_Prod.Text = row.Cells[1].Text.ToString(); lbl_Quant.Text = row.Cells[3].Text.ToString(); lbl_Fprod.Text = row.Cells[1].Text.ToString(); lbl_Fsquant.Text = row.Cells[3].Text.ToString(); Button Btn = (Button)e.CommandSource; GridViewRow myRow = (GridViewRow)Btn.Parent.Parent; GridView myGrid = (GridView)sender; hd_sno1.Value = myGrid.DataKeys[myRow.RowIndex].Values[0].ToString(); //getting data hd_branch.Value = myGrid.DataKeys[myRow.RowIndex].Values[1].ToString();//getting } }
CommandField cf = new CommandField(); cf.ButtonType = ButtonType.Button; cf.ShowCancelButton = true; cf.ShowEditButton = true; gv.Columns.Add(cf);
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)