<asp:GridView ID="GVProductOrder" runat="server" AutoGenerateColumns="false" GridLines="Vertical" Height="200" Width="1050"> <HeaderStyle CssClass="HeaderStyleGrid" /> <Columns> <asp:BoundField DataField="ItemCode" HeaderText="Item Code" HeaderStyle-Width="150px"/> <asp:BoundField DataField="ItemName" HeaderText="Item Name" HeaderStyle-Width="500px"/> <asp:BoundField DataField="EanCode" HeaderText="Ean Code" HeaderStyle-Width="100px"/> <asp:BoundField DataField="Cost" HeaderText="Cost" HeaderStyle-Width="150px"/> <asp:BoundField DataField="MRP" HeaderText="MRP" HeaderStyle-Width="150px"/> <asp:BoundField DataField="SP" HeaderText="SP" HeaderStyle-Width="150px"/> <asp:BoundField DataField="MBQ" HeaderText="MBQ" HeaderStyle-Width="100px"/> <asp:BoundField DataField="Quantity" HeaderText="Quantity" HeaderStyle-Width="100px"/> <asp:BoundField DataField="FreeQty" HeaderText="Free Qty" HeaderStyle-Width="100px"/> <asp:BoundField DataField="FixedDisc" HeaderText="Fixed Disc" HeaderStyle-Width="100px"/> <asp:BoundField DataField="Tax" HeaderText="Tax" HeaderStyle-Width="100px"/> <asp:BoundField DataField="Value" HeaderText="Value" HeaderStyle-Width="100px"/> <asp:BoundField DataField="OnOrder" HeaderText="On Order" HeaderStyle-Width="100px"/> <asp:BoundField DataField="Remarks" HeaderText="Remarks" HeaderStyle-Width="500px"/> <asp:BoundField DataField="Type" HeaderText="Type" HeaderStyle-Width="100px"/>
using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Data.SqlClient; public partial class PurchaseOrder1 : System.Web.UI.Page { DataTable dt = new DataTable(); protected void GVProductOrderBind() { ViewState["GVTable"]=dt; GVProductOrder.DataSource = dt; GVProductOrder.DataBind(); } protected void InsertToGrid() { } protected void Page_Load(object sender, EventArgs e) { try { DataRow dr = null; dt.Columns.Add("ItemCode"); dt.Columns.Add("ItemName"); dt.Columns.Add("EanCode"); dt.Columns.Add("Cost"); dt.Columns.Add("MRP"); dt.Columns.Add("SP"); dt.Columns.Add("MBQ"); dt.Columns.Add("Quantity"); dt.Columns.Add("FreeQty"); dt.Columns.Add("FixedDisc"); dt.Columns.Add("Tax"); dt.Columns.Add("Value"); dt.Columns.Add("OnOrder"); dt.Columns.Add("Remarks"); dt.Columns.Add("Type"); dr = dt.NewRow(); dt.Rows.Add(dr); GVProductOrderBind(); } catch (Exception ex) { throw ex; } } protected void BtnClose_Click(object sender, EventArgs e) { Response .Redirect ("~/Welcome.aspx"); } protected void BtnSave_Click(object sender, EventArgs e) { try { if (ViewState["GVTable"] != null) { DataTable dtCurrentTable = (DataTable)ViewState["GVTable"]; DataRow drCurrentRow = null; if (dtCurrentTable.Rows.Count > 0) { for (int i = 1; i <= dtCurrentTable.Rows.Count; i++) { drCurrentRow = dtCurrentTable.NewRow(); drCurrentRow["ItemCode"] = TxtItemCode.Text; drCurrentRow["ItemName"] = TxtItemDescription.Text; drCurrentRow["EanCode"] = TxtEanCode.Text; drCurrentRow["Cost"] = TxtCP.Text; drCurrentRow["MRP"] = TxtMRP.Text; drCurrentRow["SP"] = TxtSP.Text; drCurrentRow["MBQ"] = TxtACP.Text; drCurrentRow["Quantity"] = TxtQty.Text; drCurrentRow["FreeQty"] = TxtFreeQty.Text; drCurrentRow["FixedDisc"] = TxtDiscPercentage.Text; drCurrentRow["Tax"] = TxtTaxPercentage.Text; drCurrentRow["Value"] = TxtValue.Text; drCurrentRow["OnOrder"] = TxtOnOrder.Text; drCurrentRow["Remarks"] = TxtQOH.Text; drCurrentRow["Type"] = TxtUOP.Text; } dtCurrentTable.Rows.Add(drCurrentRow); //Store the current data to ViewState ViewState["CurrentTable"] = dtCurrentTable; //Rebind the Grid with the current data GVProductOrder.DataSource = dtCurrentTable; GVProductOrder.DataBind(); } } else { Response.Write("ViewState is null"); } SetPreviousData(); } catch (Exception ex) { throw ex; } } private void SetPreviousData() { //int rowIndex = 0; if (ViewState["CurrentTable"] != null) { DataTable dt = (DataTable)ViewState["CurrentTable"]; if (dt.Rows.Count > 0) { for (int i = 1; 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"); //TextBox box3 = (TextBox)Gridview1.Rows[rowIndex].Cells[3].FindControl("TextBox3"); //box1.Text = dt.Rows[i]["ItemCode"].ToString(); //box2.Text = dt.Rows[i]["Column2"].ToString(); //box3.Text = dt.Rows[i]["Column3"].ToString(); DataRow drCurrentRow = dt.NewRow(); drCurrentRow["ItemCode"] = TxtItemCode.Text; drCurrentRow["ItemName"] = TxtItemDescription.Text; drCurrentRow["EanCode"] = TxtEanCode.Text; drCurrentRow["Cost"] = TxtCP.Text; drCurrentRow["MRP"] = TxtMRP.Text; drCurrentRow["SP"] = TxtSP.Text; drCurrentRow["MBQ"] = TxtACP.Text; drCurrentRow["Quantity"] = TxtQty.Text; drCurrentRow["FreeQty"] = TxtFreeQty.Text; drCurrentRow["FixedDisc"] = TxtDiscPercentage.Text; drCurrentRow["Tax"] = TxtTaxPercentage.Text; drCurrentRow["Value"] = TxtValue.Text; drCurrentRow["OnOrder"] = TxtOnOrder.Text; drCurrentRow["Remarks"] = TxtQOH.Text; drCurrentRow["Type"] = TxtUOP.Text; //rowIndex++; } } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)