asp.net - refresh update panel from cascading drop down list -
i developing webpage utilize 2 cascading drop down lists , update panel contains nested gridview.
i have managed cascading drop down lists work correctly, , have managed nested gridview working.
the next step populate gridview based on selection of second cascading drop down list, update panel comes play. figured once selection has been made second drop down list, refresh update panel , load nested gridviews. looking through documentation, realized needed trigger of sort force update panel reload, must not doing correctly...
within update panel, use trigger parameter, cddmachine name of second drop down list.
<triggers> <asp:asyncportbacktrigger controlid="cddmachine" eventname="selectedindexchanged" /> </triggers> upon running code, following error thrown:
control id 'cddmachine' being registered through registerasyncpostbackcontrol or registerpostbackcontrol must implement either inamingcontainer, ipostbackdatahandler, or ipostbackeventhandler after searching while, have been unable find clear information how 1 go refreshing update panel means of cascading drop down list. i'm sure i'm overlooking simple, not sure need for.
edit - included code
lockout.aspx
<%@ page title="" language="vb" autoeventwireup="true" masterpagefile="~/site.master" codebehind="lockout.aspx.vb" inherits="lockouttagout.lockout" %> <%@ register assembly="ajaxcontroltoolkit" namespace="ajaxcontroltoolkit" tagprefix="asp" %> <asp:content id="bodycontent" contentplaceholderid="maincontent" runat="server"> <asp:scriptmanager id="asm" runat="server" /> <div> complex: <asp:dropdownlist id="complexlist" runat="server" /> machine: <asp:dropdownlist id="machinelist" runat="server" autopostback="true" /> <asp:cascadingdropdown id="cddcomplex" runat="server" servicepath="~/lockoutservice.asmx" servicemethod="getcomplex" targetcontrolid="complexlist" category="complex" prompttext="select complex" /> <asp:cascadingdropdown id="cddmachine" runat="server" servicepath="~/lockoutservice.asmx" servicemethod="getmachine" targetcontrolid="machinelist" parentcontrolid="complexlist" category="machine" prompttext="select machine" /> </div> <div> <asp:updatepanel runat="server"> <contenttemplate> <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:lotoconnectionstring %>" selectcommand="select * [devices] machine_id = @machine_id"> <selectparameters> <asp:controlparameter name="machine_id" controlid="cddmachine" propertyname="selectedvalue" /> </selectparameters> </asp:sqldatasource> <asp:gridview id="gridview1" gridlines="none" runat="server" allowsorting="true" autogeneratecolumns="false" datakeynames="devices_id" datasourceid="sqldatasource1" alternatingrowstyle-backcolor="white"> <columns> <asp:boundfield datafield="devices_id" headertext="id" insertvisible="false" readonly="true" sortexpression="devices_id" /> <asp:boundfield itemstyle-horizontalalign="center" datafield="description" headertext="description" sortexpression="description" /> <asp:boundfield itemstyle-horizontalalign="center" datafield="location" headertext="location" sortexpression="location" /> <asp:boundfield itemstyle-horizontalalign="center" datafield="verification" headertext="verification" sortexpression="verification" /> <asp:boundfield itemstyle-horizontalalign="center" datafield="rack_num" headertext="rack_#" sortexpression="rack_num" /> <asp:boundfield itemstyle-horizontalalign="center" datafield="section_num" headertext="section_#" sortexpression="section_num" /> <asp:boundfield itemstyle-horizontalalign="center" datafield="color_or_number" headertext="key_identifier" sortexpression="color_or_number" /> <asp:boundfield itemstyle-horizontalalign="center" datafield="normal_position" headertext="normal_position" sortexpression="normal_position" /> <asp:templatefield headertext="p&p numbers" controlstyle-width="100px"> <itemtemplate> <asp:sqldatasource id="sqldatasource2" runat="server" connectionstring="<%$ connectionstrings:lotoconnectionstring %>" selectcommand="select * [pnp] ([devices_id] = @devices_id)"> <selectparameters> <asp:parameter name="devices_id" type="int32" /> </selectparameters> </asp:sqldatasource> <asp:gridview id="gridview2" showheader="false" gridlines="none" runat="server" autogeneratecolumns="false" datakeynames="pnp_id" datasourceid="sqldatasource2"> <columns> <asp:boundfield itemstyle-horizontalalign="center" datafield="pnp_num" headertext="pnp_num" sortexpression="pnp_num" /> </columns> </asp:gridview> </itemtemplate> </asp:templatefield> </columns> <headerstyle backcolor="#a52138" forecolor="white" font-size="medium" /> </asp:gridview> </contenttemplate> </asp:updatepanel> </div> lockout.aspx.vb
public class lockout inherits system.web.ui.page protected sub page_load(byval sender object, byval e system.eventargs) handles me.load, machinelist.selectedindexchanged end sub protected sub gridview1_rowdatabound(byval sender object, byval e system.web.ui.webcontrols.gridviewroweventargs) handles gridview1.rowdatabound if e.row.rowtype = datacontrolrowtype.datarow dim s sqldatasource = ctype(e.row.findcontrol("sqldatasource2"), sqldatasource) s.selectparameters(0).defaultvalue = e.row.cells(0).text end if end sub end class lockoutservice.asmx.vb
imports system.web.services imports system.web.services.protocols imports system.componentmodel imports ajaxcontroltoolkit imports system.data.sqlclient ' allow web service called script, using asp.net ajax, uncomment following line. <system.web.script.services.scriptservice()> _ <system.web.services.webservice(namespace:="http://tempuri.org/")> _ <system.web.services.webservicebinding(conformsto:=wsiprofiles.basicprofile1_1)> _ <toolboxitem(false)> _ public class lockoutservice inherits system.web.services.webservice <webmethod()> _ public function getcomplex(byval knowncategoryvalues string, byval category string) cascadingdropdownnamevalue() dim conn new sqlconnection("data source=wiwrms-sqld2\sqld2;initial catalog=loto;persist security info=true;user id=loto_admin;password=lotoadmin") conn.open() dim comm new sqlcommand( _ "select * complex", conn) dim dr sqldatareader = comm.executereader() dim l new list(of cascadingdropdownnamevalue) while (dr.read()) l.add(new cascadingdropdownnamevalue(dr("complex_name").tostring(), dr("complex_id").tostring())) end while conn.close() return l.toarray() end function <webmethod()> _ public function getmachine(byval knowncategoryvalues string, byval category string) cascadingdropdownnamevalue() dim complex_id integer dim kv stringdictionary = cascadingdropdown.parseknowncategoryvaluesstring(knowncategoryvalues) if not kv.containskey("complex") or not int32.tryparse(kv("complex"), complex_id) throw new argumentexception("couldn't find complex.") end if dim conn new sqlconnection("data source=wiwrms-sqld2\sqld2;initial catalog=loto;persist security info=true;user id=loto_admin;password=lotoadmin") conn.open() dim comm new sqlcommand( _ "select * machine complex_id = @complex_id", conn) comm.parameters.addwithvalue("@complex_id", complex_id) dim dr sqldatareader = comm.executereader() dim l new list(of cascadingdropdownnamevalue) while (dr.read()) l.add(new cascadingdropdownnamevalue(dr("machine_name").tostring(), dr("machine_id").tostring())) end while conn.close() return l.toarray() end function end class
a cascadingdropdown extender on dropdownlist, should able remove trigger, set final dropdownlist's autopostback property true, handle selectedindexchanged event. should automatically trigger partialpostback can update gridview accordingly.
additional details fix:
i'm thinking may want change following in datasource markup: <asp:controlparameter name="machine_id" controlid="cddmachine" propertyname="selectedvalue" /> change controlid machinelist.
Comments
Post a Comment