using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Sql; using System.Data.SqlClient; public partial class admin_product_attribute : System.Web.UI.Page { SqlConnection con; SqlCommand comm; protected void Page_Load(object sender, EventArgs e) { int ProductId, CategoryId; if (Page.IsPostBack == false) { ProductId = Convert.ToInt32(Session["ProductId"].ToString()); CategoryId = Convert.ToInt32(Session["CategoryId"].ToString()); ViewState.Add("ProductId", ProductId); ViewState.Add("CategoryId", CategoryId); con = new SqlConnection(MyConnection.GetConnectionString()); con.Open(); String selectquery = "select * from attribute where category_id=" + CategoryId; comm = new SqlCommand(selectquery, con); SqlDataReader reader = comm.ExecuteReader(); Table table = new Table(); table.Style.Add("margin", "auto"); table.ID = "Table1"; Page.Form.Controls.Add(table); int i = 0, j = 0; while (reader.Read() != false) { // Label1.Text = Label1.Text + "<br />" + reader.GetString(reader.GetOrdinal("title")); TableRow row = new TableRow(); TableCell cell = new TableCell(); Label lb = new Label(); lb.Text = reader.GetString(reader.GetOrdinal("title")); lb.ID = Convert.ToString(i); cell.Controls.Add(lb); row.Cells.Add(cell); TableCell cell2 = new TableCell(); TextBox tb = new TextBox(); tb.ID = Convert.ToString(j); cell2.Controls.Add(tb); row.Cells.Add(cell2); i++; j++; table.Rows.Add(row); } ViewState.Add("AttributeCounti", i); ViewState.Add("AttributeCountj", j); Panel1.Controls.Add(table); reader.Close(); } } protected void btnproattribute_Click(object sender, EventArgs e) { int ProductId, CategoryId, AttributeCounti, AttributeCountj; ProductId = Convert.ToInt32(ViewState["ProductId"].ToString()); CategoryId = Convert.ToInt32(ViewState["CategoryId"].ToString()); AttributeCounti = Convert.ToInt32(ViewState["AttributeCounti"].ToString()); AttributeCountj = Convert.ToInt32(ViewState["AttributeCountj"].ToString()); String name, value; for (int i = 0; i < AttributeCounti; i++) { name = (Request.Form[Convert.ToString(i)].ToString()); Label2.Text = Label2.Text + "<br /> name" + name; } for(int j=0;j<attributecountj;j++)> { value = (Request.Form[Convert.ToString(j)].ToString()); Label2.Text = Label2.Text + "<br /> value" + value; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)