c# - get values from dynamically created combobox for postbackurl -


here's thing, i'm not experienced programmer , i'm creating web store scratch, can list products , and dynamically created button on each product add cart, added combobox product quantity, , here's problem.

before sending product id on url, can't find way send product quantity, because before creating url postbackurl , adding product id url, ok.

so now, need way add quantity url, don't know how dynamically created controls, created id each button , combobox + number randomly generated(both button , combobox has same number, know name of each).

btw i'm using devexpress framework.

here's code inserted container:

using system; using system.text; using system.web.dynamicdata; using system.web.ui; using system.web.ui.htmlcontrols; using system.web.ui.webcontrols; using devexpress.web; using microsoft.win32; using webarrendatariosdx.class; using system.data.sqlclient;  namespace webarrendatariosdx.productos {     public partial class productmaster : system.web.ui.page     {          protected void page_load(object sender, eventargs e)         {             getproducts();         }          private void getproducts()         {             var icc = (string) session["icc"];             var cid = (string) session["uid"];             var dbc = new dbclass();             dbc.getconnstr("dbtoconnect");             string str;             dbc.setquerytype("txt", out str);             dbc.setquery("sp_get_products @customer_id=" + cid + ", @client_id=" + icc, out str);             sqldatareader rdr = dbc.exec_ret_sqldatareader();             try             {                 while (rdr.read())                 {                     //<tabla de producto>                     var producttable = new table {cssclass = "templatetable"}; //<table></table>                     producttable.attributes.add("runat","server");                     producttable.rows.add(maketitlerow(rdr["st_desc_tipoproducto"].tostring(), rdr["id"].tostring(),                         rdr["st_codinterno_tipoproducto"].tostring()));                     //<tr></tr>                     producttable.rows.add(makecontentrow(rdr["st_desc_marcaproducto"].tostring(),                         rdr["in_precioventa_tipoproducto"].tostring(), 1)); //<tr></tr>                     producttable.rows.add(makecontentrow(rdr["st_desc_marcaproducto"].tostring(),                         rdr["in_precioventa_tipoproducto"].tostring(), 2)); //<tr></tr>                      //</tabla de producto>                     products_container.controls.add(producttable); //meter contenido la tabla                     products_container.controls.add(new literal() {text = "<br />"});                 }             }             catch (exception ex)             {                 var errortable = new table {cssclass = "templatetable"}; //<table></table>                 var errorrow = new tablerow(); //<tr></tr>                 var errorcell = new tablecell                 {                     text = "error al consultar productos: " + ex.message + "<br> intente recargando la pagina.",                     columnspan = 4,                     cssclass = "value"                 }; //<td></td>                 errorrow.cells.add(errorcell);                 errortable.rows.add(errorrow);                 products_container.controls.add(errortable);             }          }          private string tob64(string toconv)         {             byte[] bytestoencode = encoding.utf8.getbytes(toconv);             string encodedtext = convert.tobase64string(bytestoencode);             return encodedtext;         }          private tablerow maketitlerow(string productname, string imgid, string sku)         {             var titlerow = new tablerow(); //<tr></tr>             var titleimagecell = new tablecell { cssclass = "imagecell", rowspan = 3 };             var ime = new aspximage {width = 120, height = 120};             ime.imageurl = "~/util/image.ashx?id=" + imgid;             titleimagecell.controls.add(ime);             var titlecell = new tablecell {text = productname, columnspan = 3, cssclass = "value"}; //<td></td>             //**** columna con botones             var buttonscell = new tablecell { cssclass = "imagecell", rowspan = 3 };             var btn_addtocart = new aspxbutton();             var cbx_qty = new aspxcombobox(); //the combobox need value             cbx_qty.dropdownstyle = dropdownstyle.dropdownlist;             cbx_qty.items.add("cantidad...", 0);             (int = 1; < 11; i++)             {                 cbx_qty.items.add(convert.tostring(i), i);             }             cbx_qty.selectedindex = 0;             btn_addtocart.text = "agregar al carro";             var rnd = new random();             int rnds = rnd.next(6236, 6124125);             btn_addtocart.id = "btn_atc_" + rnds; //my button created dynamically custom name             string idbtn = btn_addtocart.id.tostring();             cbx_qty.id = "cbx_" + idbtn; //my custom id each combobox created dynamically             btn_addtocart.postbackurl = "~/productos/cart/cartmaster.aspx?nod=" + tob64(sku) + "&pid=" + rnds;// works need add quantity             buttonscell.controls.add(cbx_qty);             buttonscell.controls.add(btn_addtocart);             //**** /columna con botones             titlerow.cells.add(titleimagecell); //imagen del producto             titlerow.cells.add(titlecell); //titulo del producto             titlerow.cells.add(buttonscell); //agrega botones             return titlerow;         }          private tablerow makecontentrow(string manufacturer, string price, int rowno)         {             var contentrow = new tablerow(); //<tr></tr>             if (rowno == 1)             {                 var contentmanufacturertextcell = new tablecell { text = "fabricante" }; //<td></td>                 var contentmanufacturercell = new tablecell { text = manufacturer, cssclass = "value" }; //<td></td>                 contentrow.cells.add(contentmanufacturertextcell);                 contentrow.cells.add(contentmanufacturercell);             }             else if (rowno == 2)             {                 var contentpricetextcell = new tablecell { text = "precio" }; //<td></td>                 var contentpricecell = new tablecell { text = "$ " + price, cssclass = "value" }; //<td></td>                 contentrow.cells.add(contentpricetextcell);                 contentrow.cells.add(contentpricecell);             }             return contentrow;         }     } } 


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -