c# - ASP.NET Repeater Control - Getting Hiddenfield value inside the repeater control -
i have hiddenfield inside repeater control , button outside repeater control. below asp.code have.
<asp:repeater id="rptaccordian" runat="server" onitemdatabound="rptaccordian_itemdatabound"> <itemtemplate> <div class="s_panel"> <h1> <a href="#" data-content="tool tip"><%# eval("name") %></a> </h1> <div> <p> <small><span style="font-family: 'segoe ui'; font-weight: bold;">category objective: </span><span style="font-family: 'segoe ui'"><%# eval("objective") %></span></small> </p> <p> <small><span style="font-family: 'segoe ui'; font-weight: bold;">category riskscore: </span> <code><%# eval("score") %><span>%</span></code></small> </p> <p> <code> <img src="content/img/add.png" /><asp:linkbutton id="add" runat="server">add question</asp:linkbutton> </code> </p> <asp:hiddenfield id="hdncategoryid" runat="server" value='<%# bind("categoryid") %>' /> </div> </itemtemplate> </asp:repeater> <div id="modalpopup"> <asp:button id="btninsertquestion" runat="server" text="save" onclick="btninsertquestion_click" /> </div>
my backend code follows.
protected void btninsertquestion_click(object sender, eventargs e) { hiddenfield hf = (hiddenfield)rptaccordian.findcontrol("hdncategoryid"); catid = convert.toint16(hf.value); response.write("id is") + catid; }
there 13 repeaters , each repeater have different categoryid it. have link button called add inside each repeater , when press button have modal popup open , have button. on clicking button need display appropriate categoryid belongs repeater control in clicked add link button.
however, hiddenfield hf showing null , i'm not able value of hiddenfield of accordion.
you have repeater item access hiddenfield:
protected void btninsertquestion_click(object sender, eventargs e) { (int = 0; < rptaccordian.items.count; i++) { var item = rptaccordian.items[i]; var hf = item.findcontrol("hdncategoryid") hiddenfield; var val = hf.value; } }
updated
protected void add_click(object sender, eventargs e) { var lb = sender linkbutton; var par = lb.parent.findcontrol("hdncategoryid"); }
Comments
Post a Comment