asp.net - To show/hide file upload control based on value of hiddenfield in repeater -
i have 1 repeater control on asp.net page. has 1 check box, label, file upload control , 3 hiddenfields. want hide/show file upload control based on value of 1 of hidden fields.
here code snippet itemdatabound event of repeater.
protected void rptchecks_itemdatabound (object sender, repeateritemeventargs e) { hiddenfield hdid = (hiddenfield)e.item.findcontrol("hdncheckid"); hiddenfield hddocopt = (hiddenfield)e.item.findcontrol("hdndocoption"); fileupload filecheck = (fileupload)e.item.findcontrol("filedocument"); if ( convert.toint32(hddocopt.value) == 0 || convert.toint32(hddocopt.value) == 1) filecheck.visible = true; else filecheck.visible = false; }
here markup code
<asp:repeater id="rptchecks" runat="server" onitemdatabound="rptchecks_itemdatabound"> <headertemplate> <table> <tr> <th> </th> <th> </th> <th> </th> </tr> </headertemplate> <itemtemplate> <tr> <td> <asp:checkbox id="chk" runat="server" /> </td> <td style="padding-left: 10px"> <asp:label id="lblcheck" runat="server" text="<%#bind('name') %>"></asp:label> </td> <td style="padding-left: 10px"> <asp:hiddenfield id="hdndocoption" runat="server" value="<%#bind('documentoption') %>" /> <asp:hiddenfield id="hdncheckid" runat="server" value="<%#bind('id') %>" /> <asp:fileupload id="filedocument" runat="server" /> </td> </tr> </itemtemplate> <footertemplate> </table> </footertemplate> </asp:repeater>
how can this?
error: error occurred object reference not set instance of object @ if-condition.
the error when try find controls in headertemplate , use value, in case value null. should find controls in itemtemplate below:
protected void rptchecks_itemdatabound(object sender, repeateritemeventargs e) { if (e.item.itemtype == listitemtype.alternatingitem || e.item.itemtype == listitemtype.item) { hiddenfield hdid = (hiddenfield)e.item.findcontrol("hdncheckid"); hiddenfield hddocopt = (hiddenfield)e.item.findcontrol("hdndocoption"); fileupload filecheck = (fileupload)e.item.findcontrol("filedocument"); if (convert.toint32(hddocopt.value) == 0 || convert.toint32(hddocopt.value) == 1) filecheck.visible = true; else filecheck.visible = false; } }
Comments
Post a Comment