Tuesday 15 March 2011

c# - How to retain selected HTML5 radio button value when you navigate through a DataPager? -



c# - How to retain selected HTML5 radio button value when you navigate through a DataPager? -

i'm trying create online questionnaire , front-end of website

<table> <tbody> <asp:listview id="lvquestion" runat="server" onpagepropertieschanged="lvquestion_onpagepropertieschanged" onpagepropertieschanging="lvquestion_pagepropertieschanging"> <layouttemplate> <ul> <asp:placeholder id="itemplaceholder" runat="server" /> </ul> </layouttemplate> <itemtemplate> <tr runat="server"> <td><%# eval("thequestion") %></td> </tr> <tr> <td><input type="radio" name="choice" value="<%# eval("choice1") %>" /><%# eval("choice1") %></td> <td><input type="radio" name="choice" value="<%# eval("choice2") %>" /><%# eval("choice2") %></td> <td><input type="radio" name="choice" value="<%# eval("choice3") %>" /><%# eval("choice3") %></td> <td><input type="radio" name="choice" value="<%# eval("choice4") %>" /><%# eval("choice4") %></td> </tr> </itemtemplate> <emptydatatemplate> no info </emptydatatemplate> </asp:listview> </tbody> </table> <asp:datapager id="lvdatapager1" runat="server" pagedcontrolid="lvquestion" pagesize="1"> <fields> <asp:numericpagerfield buttontype="link" /> </fields> </asp:datapager>

i have displayed questions , choices(using html5 radio buttons). however, when user navigates question #1 question #2, selected reply in question #1 lost datapager. needed selected answers saved in order collect answers using single submit button.

you can utilize runat='server' providing id controls

<input type="radio" name="choice" value="<%# eval("choice1") %>" id="rdch1" runat="server" /> <input type="radio" name="choice" value="<%# eval("choice1") %>" id="rdch2" runat="server" /> <input type="radio" name="choice" value="<%# eval("choice1") %>" id="rdch3" runat="server" />

on code behind can these values by

string selvalues=rdch1.value.tostring();

you have find radio buttons within listview on itemdatabound

protected void listview_itemdatabound(object sender, listviewitemeventargs e) { if (e.item.itemtype == listviewitemtype.dataitem) { system.web.ui.htmlcontrols.htmlinputradiobutton = (system.web.ui.htmlcontrols.htmlinputradiobutton)e.item.findcontrol("rdch1"); }

c# asp.net radio-button listviewitem datapager

No comments:

Post a Comment