asp.net - Values of controls in a repeater are empty after postback -


i'm using repeater contains controls textboxes, dropdownlist, etc... populate them in item databound event in repeater. filled correctly, problem when try values in them in button_click event found them empty. here code in button_click event

location loc = new location();             foreach (repeateritem repeated in repedit.items)             {                 dropdownlist drp = (dropdownlist)repeated.findcontrol("drpdown");                 textbox txt = (textbox)repeated.findcontrol("txt");                 checkbox chk = (checkbox)repeated.findcontrol("chk");                 if (drp != null && !string.isnullorempty(drp.attributes["id"]))                 {                     loc.gettype().getproperty(drp.attributes["id"].split('#')[0] + "id").setvalue(loc, int.parse(drp.selectedvalue), null);                 }                 if (txt != null && !string.isnullorempty(txt.attributes["id"]))                 {                     if (txt.attributes["id"].contains("#int"))                     {                         loc.gettype().getproperty(txt.attributes["id"].split('#')[0]).setvalue(loc, int.parse(txt.text), null);                     }                     else if (txt.attributes["id"].contains("#decimal"))                     {                         loc.gettype().getproperty(txt.attributes["id"].split('#')[0]).setvalue(loc, decimal.parse(txt.text), null);                     }                     else                     {                         loc.gettype().getproperty(txt.attributes["id"].split('#')[0]).setvalue(loc, txt.text, null);                     }                 }                 if (chk != null && !string.isnullorempty(chk.attributes["id"]))                 {                     loc.gettype().getproperty(chk.attributes["id"].split('#')[0]).setvalue(loc, chk.checked, null);                 }             } 

and aspx is

    <asp:repeater id="repedit" runat="server" onitemdatabound="repedit_itemdatabound" onitemcommand="repedit_itemcommand" viewstatemode="enabled" enableviewstate="true">             <itemtemplate>                 <asp:label id="lblname" runat="server" visible="false" viewstatemode="enabled" enableviewstate="true"></asp:label>                 <asp:textbox id="txt" runat="server" visible="false" viewstatemode="enabled" enableviewstate="true"></asp:textbox>                 <asp:checkbox id="chk" runat="server" visible="false" viewstatemode="enabled" enableviewstate="true" />                 <asp:dropdownlist id="drpdown" runat="server" visible="false" enableviewstate="true"></asp:dropdownlist>             </itemtemplate>  </asp:repeater> 

edit***

protected void repedit_itemdatabound(object sender, repeateritemeventargs e)         {             label name = e.item.findcontrol("lblname") label;             textbox text = e.item.findcontrol("txt") textbox;             checkbox chk = e.item.findcontrol("chk") checkbox;             dropdownlist drp = e.item.findcontrol("drpdown") dropdownlist;             button = e.item.findcontrol("butedit") button;             //butedit.visible = true;             if (but != null)             {                 but.visible = true;             }             if (e.item.itemtype == listitemtype.item)             {                 keyvaluepair<string, dictionary<int, string>> kvp = (keyvaluepair<string, dictionary<int, string>>)e.item.dataitem;                 if (name != null)                 {                     if (kvp.key.contains("#datetime"))                     {                         return;                     }                     name.visible = true;                     name.text = kvp.key.split('#')[0].tostring();                 }                 if (kvp.key.contains("#int") || kvp.key.contains("#decimal"))                 {                     text.visible = true;                     text.id = kvp.key;                     text.enableviewstate = true;                     text.attributes["id"] = kvp.key;                     text.text = kvp.value[0].tostring();                     if (kvp.key.split('#')[0] == "id")                     {                         text.enabled = false;                     }                 }                 else if (kvp.key.contains("#bool"))                 {                     chk.visible = true;                     chk.id = kvp.key;                     chk.attributes["id"] = kvp.key;                     chk.enableviewstate = true;                     string value = kvp.value[0].tostring();                     if (value.contains("true"))                     {                         chk.checked = true;                     }                 }                 else if (kvp.key.contains("#string"))                 {                     e.item.findcontrol("txt").id = kvp.key;                     text.id = kvp.key;                     text.enableviewstate = true;                     text.visible = true;                     text.attributes["id"] = kvp.key;                     text.text = kvp.value[0].tostring();                 }                  else                 {                     drp.id = kvp.key.split('#')[0] + "#0";                     drp.attributes["id"] = drp.id;                     drp.enableviewstate = true;                     drp.visible = true;                     drp.datasource = kvp.value;                     drp.datatextfield = "value";                     drp.datavaluefield = "key";                     drp.databind();                     string x = kvp.key.split('#')[1];                     listitem temp = drp.items.findbyvalue(x);                     if (temp != null)                     {                         drp.items.findbyvalue(x).selected = true;                     }                 }             }         } 

so 1 tell me problem?


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -