asp.net - My RadioButtonList won't append Query String or show selected value after Postback - C# & .Net -
i have 2 issues. on aspx page, have 3 radiobuttonlists (aka rbl)that gets each of data database table. upon selection on rbl, postback occurs same page , value of specific rbl gets entered querystring, listview looking for, filter out products based on querystring. list view works fine when reads querystring filters list down.
issue 1 - on postback, value selected of 3 rbl's, doesn't selected when page loads. rbl's don't have value, if have default value set on page. how page reload values selected in rbl's you've chosen?
issue 2 - if make selection on of other 2 rbl's, instead of updating querystring, wipes out first value when posts again. if pick in rbl-1, posts specific field updated in querystring, if pick in rbl-2, posts value rbl-2, , wipes out value picked rbl-1. how can page load, while keeping of prior selections in querystring?
aspx code: <p>normally open or closed:<asp:radiobuttonlist id="radiobuttonlist1" runat="server" enableviewstate="true" autopostback="true" datasourceid="normalitysds" datatextfield="op" datavaluefield="op" onselectedindexchanged="radiobuttonalllists_selectedindexchanged"> </asp:radiobuttonlist> <asp:sqldatasource id="normalitysds" runat="server" connectionstring="<%$ 005 %>" selectcommand="select distinct [op] [matrix] order [op]"> </asp:sqldatasource> </p> <p>sizes:<asp:radiobuttonlist id="radiobuttonlist2" runat="server" enableviewstate="true" autopostback="true" datasourceid="sizessds" datatextfield="size" repeatcolumns="2" datavaluefield="size" onselectedindexchanged="radiobuttonalllists_selectedindexchanged"> </asp:radiobuttonlist> <asp:sqldatasource id="sizessds" runat="server" connectionstring="<%$ 005 %>" selectcommand="select distinct [size] [matrix] order [size]"> </asp:sqldatasource> </p> <p>body:<asp:radiobuttonlist id="radiobuttonlist3" runat="server" enableviewstate="true" autopostback="true" datasourceid="bodysds" datatextfield="body" datavaluefield="body" onselectedindexchanged="radiobuttonalllists_selectedindexchanged"> </asp:radiobuttonlist> <asp:sqldatasource id="bodysds" runat="server" connectionstring="<%$ 005 %>" selectcommand="select distinct [body] [matrix] order [body]"> </asp:sqldatasource> <selectparameters> <asp:querystringparameter defaultvalue="nc" name="op" querystringfield="op" type="string" /> <asp:querystringparameter defaultvalue="0.25" name="sz" querystringfield="sz" type="string" /> <asp:querystringparameter defaultvalue="304" name="body" querystringfield="body" type="string" /> </selectparameters>
code-behind:
using system; using system.collections.generic; using system.linq; using system.web; using system.web.ui; using system.web.ui.webcontrols; namespace configurator { public partial class product_config_full_wquery : system.web.ui.page { string baseurl = "/product_config_full_wquery.aspx"; string op; string op2; string sz; string body; protected void page_load(object sender, eventargs e) { if (!page.ispostback) { op = (server.urldecode(request.querystring["op"] )); radiobuttonlist1.selectedindex = op2; radiobuttonlist1.databind(); sz = server.urldecode(request.querystring["sz"]); body = server.urldecode(request.querystring["body"]); } } // combining actions single protected-event protected void radiobuttonalllists_selectedindexchanged(object sender, eventargs e) { op = radiobuttonlist1.selectedvalue.tostring(); sz = radiobuttonlist2.selectedvalue.tostring(); body = radiobuttonlist3.selectedvalue.tostring(); if (op != null) { baseurl += "?op=" + op + "&"; } //else op = "nc"; if (sz != null) { baseurl += "sz=" + sz + "&"; } if (body != null) { baseurl += "body=" + body + "&"; } response.redirect(string.format(baseurl, server.urlencode(op), server.urlencode(sz), server.urlencode(body))); }
since you're dynamically setting values inside radio button list, values page setting controls aren't there on postback (page lifecycle trying set values controls before data sources retrieve possible values , add items control itself).
also, stop using querystring hold postback values - if need to, set hiddenfields hold information, persist through postbacks , won't have worry odd querystring issues
Comments
Post a Comment