asp.net - List search result in Listbox -
for new admin. function of application, there gridview
show records in database.
there textbox
let user input staff name , click "search" button. want show search result in listbox
(show similar staff name). when user click on name, automatically insert db , refresh gridview
.
how can databind listbox
based on textbox
? , how can insert value when user click listbox
? thanks.
<%@ page language="vb" autoeventwireup="false" codefile="italert.aspx.vb" inherits="departmentmanager_italert" %> <%@ register tagprefix="telerik" namespace="telerik.web.ui" assembly="telerik.web.ui" %> <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div style="width: 500px; margin-left: auto; margin-right: auto;"> <telerik:radscriptmanager id="radscriptmanager1" runat="server"> </telerik:radscriptmanager> <asp:label id="label1" runat="server" text="staffs email alert:" font-bold="true"></asp:label> <br /><br /> <telerik:radgrid id="radgrid1" runat="server" allowsorting="true" allowpaging="true" autogeneratecolumns="false" datasourceid="lds" gridlines="none" pagesize="20" allowautomaticdeletes="true" style="border: 0; outline: none;" ondeletecommand="radgrid1_deletecommand"> <clientsettings allowcolumnsreorder="true" reordercolumnsonclient="true"> <selecting allowrowselect="true" /> </clientsettings> <mastertableview datasourceid="lds" datakeynames="id"> <commanditemsettings exporttopdftext="export pdf"> </commanditemsettings> <rowindicatorcolumn filtercontrolalttext="filter rowindicator column"> <headerstyle width="20px"></headerstyle> </rowindicatorcolumn> <expandcollapsecolumn filtercontrolalttext="filter expandcolumn column"> <headerstyle width="20px"></headerstyle> </expandcollapsecolumn> <columns> <telerik:gridboundcolumn datafield="displayname" filtercontrolalttext="filter name column" headertext="staff name" readonly="true" sortexpression="displayname" uniquename="displayname"> </telerik:gridboundcolumn> <telerik:gridbuttoncolumn confirmtext="delete record?" confirmdialogtype="radwindow" confirmtitle="delete" buttontype="imagebutton" text="delete" commandname="delete" /> </columns> <editformsettings> <editcolumn filtercontrolalttext="filter editcommandcolumn column"> </editcolumn> </editformsettings> </mastertableview> <filtermenu enableimagesprites="false"> </filtermenu> <headercontextmenu cssclass="gridcontextmenu gridcontextmenu_default"> </headercontextmenu> </telerik:radgrid> <asp:linqdatasource id="lds" runat="server" contexttypename="datacontext" orderby="displayname" select="new (id, displayname)" tablename="v_emailalerts" where="type == 4"> <whereparameters> <asp:querystringparameter name="cid" querystringfield="cid" type="int32" /> </whereparameters> </asp:linqdatasource> <br /> <br /> <asp:textbox runat="server" id="tb_staffname"> </asp:textbox> <asp:button id="btnsearch" runat="server" text="search" onclick="btnsearch_click"/> <telerik:radlistbox runat="server" id="radlistbox_staff" height="300px" width="230px" allowtransfer="false" autopostback="false" style="top: 0px; left: 0px" datasourceid="lds_staff" datatextfield="displayname" datavaluefield="sid" > </telerik:radlistbox> <asp:linqdatasource id="lds_staff" runat="server" contexttypename="dchrisdatacontext" orderby="displayname" select="new (sid, displayname)" tablename="vhris_staffdbs" where="lefe == false , sid nothing"> </asp:linqdatasource> </div> </form> </body> </html>
code behind (with proposed listbox databind function) :
imports telerik.web.ui partial class departmentmanager_italert inherits system.web.ui.page protected sub page_load(byval sender object, byval e eventargs) end sub protected sub radgrid1_deletecommand(byval source object, byval e gridcommandeventargs) handles radgrid1.deletecommand dim alertid = directcast((directcast(e.item, griddataitem)).getdatakeyvalue("id"), integer) 'retrive entity form db dim dc new datacontext dim rec = (from in dc.emailalerts a.id = alertid).firstordefault if rec isnot nothing dc.hris_emailalerts.deleteonsubmit(rec) dc.submitchanges() end if end sub protected sub btnsearch_click(byval sender object, byval e system.eventargs) handles btnsearch.click dim sname string = "" sname = tb_staffname.text if sname <> "" dim dc new dchrisdatacontext dim rec = (from in dc.vhris_staffdbs a.lefe = false _ , (x >= x.displayname.matches(sname)) select a.sid, _ a.displayname order displayname).tolist radlistbox_staff.datatextfield = "displayname" radlistbox_staff.datavaluefield = "sid" radlistbox_staff.datasource = dt radlistbox_staff.databind() end if end sub end class
moreover, display error linq of searching function
dim rec = (from in dc.vhris_staffdbs a.lefe = false _ , (x >= x.displayname.matches(sname)) select a.sid, _ a.displayname order displayname).tolist
make things bit simpler... move edit form user control entry this:
<editformsettings editformtype="webusercontrol" usercontrolname="adminlookup.ascx">
in adminlookup.ascx
add radsearchbox bound list of users want able lookup. should able debug , work through issues lookup query in isolated user control.
a demo of functionality can found here: http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/linqdatasource/defaultcs.aspx
Comments
Post a Comment