'a tıklayın. Verileri metin kutularından almak istiyorum ve bu butona tıklayarak o verilerin GridView
'a eklenmesini istiyorum. Her tıklamada yeni bir satır oluşturulmalı ve eski satır kaldırılmamalıdır. Yeni verilere her girdiğimde ve butonuna bastığımda eski satırım silinir ve yerine yeni satır kaydedilir. Tekrar tablo sütunları oluşturmak postback her zaman gridVIEWData();
arayarak Bunun nedeniTextbox'lardan GridView'a veri eklemek için butona tıklayın ASP.NET
DataTable dt1 = new DataTable();
bool flag = false;
private void gridVIEWData()
{
dt1.Columns.Add("pName", typeof(string));
dt1.Columns.Add("pCategory", typeof(string));
dt1.Columns.Add("price", typeof(string));
dt1.Columns.Add("pQuantity", typeof(string));
dt1.Columns.Add("totalPrice", typeof(string));
}
protected void Button3_Click(object sender, EventArgs e)
{
if (!flag)
{
gridVIEWData();
flag = true;
Int32 total = Convert.ToInt32(txt_quantity.Text) * Convert.ToInt32(txt_price.Text);
DataRow dr = dt1.NewRow();
dr["pName"] = DropDownList2.SelectedItem;
dr["pCategory"] = DropDownList1.SelectedItem;
dr["price"] = txt_price.Text;
dr["pQuantity"] = txt_quantity.Text;
dr["totalPrice"] = total;
dt1.Rows.Add(dr);
GridView1.DataSource = dt1;
GridView1.DataBind();
}
else if (!IsPostBack)
{
Int32 total = Convert.ToInt32(txt_quantity.Text) * Convert.ToInt32(txt_price.Text);
DataRow dr = dt1.NewRow();
dr["pName"] = DropDownList2.SelectedItem;
dr["pCategory"] = DropDownList1.SelectedItem;
dr["price"] = txt_price.Text;
dr["pQuantity"] = txt_quantity.Text;
dr["totalPrice"] = total;
dt1.Rows.Add(dr);
GridView1.DataSource = dt1;
GridView1.DataBind();
}
}
'Page_Load' içinde ne olur? Düğmelerinizi yeniden adlandırmayı düşünün. Button3'ün amacı belli değil. –