asp.net - Unable to retrieve the value of textbox inside repeater, when repeater is bound to datatable at postback -
i have repeater bound datatable last column of repeater has textbox (not programmatically created). have button outside repeater. in button_click event wanted value entered in textbox data in row of repeater. in/during postback, datatable again recreated , bounded repeater, in button_click event textbox empty (assuming user entered value , click button). have done rebinding of answer when googling it. im not sure if databinding of datatable repeater affects textbox column since column not part of datatable? how go it? please see html , behind code below,
html
<div id="ucprodres-any-mfg"> <asp:repeater id="rptanymfg" runat="server" > <itemtemplate> <div id="ucprodres-any-mfg-row"> <div class="ucprodres-stock manufacturer"> <div class="ucprodres-mfg "> <div id="ucprodres-exp-any-mfg" data-swap="-">+</div> <div> <%#databinder.eval(container.dataitem, "mfg")%></div> </div> </div> <div class="ucprodres-stock qty-avail"> <%#databinder.eval(container.dataitem, "qty")%> </div> <div class="ucprodres-stock availability"> <%#databinder.eval(container.dataitem, "availability")%> </div> <div class="ucprodres-stock unit-price"> <%#databinder.eval(container.dataitem, "qtyrange")%> </div> <div class="ucprodres-stock dollar"> <%#databinder.eval(container.dataitem, "qtyrangeprice")%> </div> <div id="txtboxid" class="ucprodres-stock qty-required" > <asp:textbox id="tbxanymfg" runat="server" style="text-align: right" tooltip="quantity should not more available quantity."></asp:textbox> <div class="ucprodres-txtbox-info">quantity should not more available quantity</div> </div> </div> </itemtemplate> </asp:repeater> </div>
behind code
public sub button_click(sender object, e eventargs) handles button.click each rptitems repeateritem in rptanymfg.items if (rptitems.itemtype = listitemtype.item) or (rptitems.itemtype = listitemtype.alternatingitem) dim tbxqtyreqd textbox = rptitems.findcontrol("tbxanymfg") if not string.isnullorempty(tbxqtyreqd.text) if tbxqtyreqd.text > "0" dim mfg string = rptitems.dataitem("mfg").tostring dim qty string = rptitems.dataitem("qty").tostring dim avail string = rptitems.dataitem("availability").tostring dim qtyrange string = rptitems.dataitem("qtyrange").tostring dim unitprice string = rptitems.dataitem("qtyrangeprice").tostring dim qtyreqd string = tbxqtyreqd.text dim rfqpart new parts.instock dim rfqpartdetails new parts.instock.partsdata(mfg, qty, avail, qtyrange, unitprice, qtyreqd) rfqpart.add(rfqpartdetails) end if end if end if next end sub
i'm not @ vb syntax put sample in c# , can convert vb yourself.
first of need make sure bind repeater control once on page postback make sure have code on page_load method:
protected void page_load(object sender, eventargs e) { if (!ispostback) bindrepeater(); } void bindrepeater() { rptanymfg.datasource = getdatafromdb(); rptanymfg.databind(); }
then on button_click event check the textbox control before unboxing textbox control below:
protected void button1_click(object sender, eventargs e) { foreach (repeateritem item in rptanymfg.items) { if (item.itemtype == listitemtype.item || item.itemtype == listitemtype.alternatingitem) { if ((textbox)item.findcontrol("tbxanymfg") != null && !string.isnullorempty(((textbox)item.findcontrol("tbxanymfg")).text)) { int value; string text = ((textbox)item.findcontrol("tbxanymfg")).text; if (!string.isnullorempty(text) && int.tryparse(text, out value)) { if (value > 0) { // value assignments here } } } } } }
just improve code it's if check textbox value integer before compare in if statement.
let me know if having trouble use code.
Comments
Post a Comment