I have one form in which 5 textboxes for product id ,qty,price,amount..when i enter the data and press "add" button it is getting placed in gridview.....but when i add another product with some other qty it addd it and remove the previous.it is showing one data which is currently.i don't want to loose previous it should add row wise...how can i achieve this.following is the coding
protected void Page_Load(object sender, EventArgs e)
{
DataTable dtDetails = new DataTable();
DataTable dt = new DataTable();
dt = objprdt.getproducts();
ddlprdcts.DataSource = dt;
ddlprdcts.DataValueField = "Product_Id";
ddlprdcts.DataTextField = "Product_Name";
ddlprdcts.DataBind();
ddlprdcts.Items.Add(new ListItem("- Please Select -", "-1"));
ddlprdcts.SelectedValue = "-1";
if (!this.IsPostBack)
{
dtDetails.Clear();
if (dtDetails.Columns.Count == 0)
{
dtDetails.Columns.Add("sl_no", typeof(int));
dtDetails.Columns.Add("productname", typeof(string));
dtDetails.Columns.Add("qty", typeof(double));
dtDetails.Columns.Add("price", typeof(decimal));
dtDetails.Columns.Add("amount", typeof(long));
}
}
public void filldtDetails()
{
dtDetails.Clear();
if (dtDetails.Columns.Count == 0)
{
dtDetails.Columns.Add("productname", typeof(string));
dtDetails.Columns.Add("qty", typeof(double));
dtDetails.Columns.Add("price", typeof(decimal));
dtDetails.Columns.Add("amount", typeof(double));
}
if (grdDetails.Rows.Count != 0)
{
for (int i = 0; i < Convert.ToInt32(ddlprdcts.Items.Count); i++)
{
dtDetails.Rows.Add(grdDetails.Rows[i].Cells[1].Text, grdDetails.Rows[i].Cells[2].Text, grdDetails.Rows[i].Cells[3].Text, grdDetails.Rows[i].Cells[4].Text);
}
}
}
on button click
filldtDetails();
DataRow dr1 = dtDetails.NewRow();
dr1[0] = TextBox2.Text;
dr1[1] = TextBox4.Text;
dr1[2] = TextBox3.Text;
dr1[3] = TextBox5.Text;
dtDetails.Rows.Add(dr1);
grdDetails.DataSource = dtDetails;
grdDetails.DataBind();
on source code
Enter Email ID <asp:TextBox ID="TextBox1" runat="server"
style="margin-bottom: 0px"></asp:TextBox>
<br />
<br />
Name
<asp:TextBox ID="TextBox2" runat="server" ontextchanged="TextBox2_TextChanged"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Select" />
<br />
product
<asp:DropDownList ID="ddlprdcts" runat="server"
onselectedindexchanged="ddlprdcts_SelectedIndexChanged"> </asp:DropDownList>
<asp:Button ID="select" runat="server" onclick="select_Click" Text="select" />
<br />
<br />
product cost <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<br />
Product qty <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<br />
<br />
product total amount <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:Button ID="Button3" runat="server" onclick="Button3_Click"
Text="calculate" />
<asp:Button ID="Button2" runat="server" Height="22px" onclick="Button2_Click"
Text="Add to cart" Width="79px" />
<br />
<asp:GridView ID="grdDetails" runat="server" Height="139px" Width="507px">
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="Edit" Text="Edit" />
<asp:ButtonField ButtonType="Button" CommandName="Delete" Text="remove" />
</Columns>
</asp:GridView>
<br />
<br />
<asp:Button ID="Button4" runat="server" Height="26px" Text="total amount" />
<asp:Label ID="Label1" runat="server"></asp:Label>
i don't want to add it into database.i just want to show it runtime only
pls help