mysql - How can I set current user as default value in the drop down list ASP.Net and VB.Net application -


in asp.net , vb.net web application form ; drop down list main contact holds list of names. list different different user logged in application.

data populated select query database fields. (select query fetches data innerjoining 2 tables- employeruser table & user table. primary key of user table id foreign key in employeruser table named userid.)

in front end asp.net coding is

               <div class="form-element">                     <label>                         main contact (required)                     </label>                     <asp:dropdownlist id="commaincontact" runat="server" cssclass="chosen" enableviewstate="true"                         datatextfield="name" datavaluefield="id" />                 </div> 

in end vb.net coding drop down list is

       commaincontact.datasource = localhelper.cachedemployeruserlist(localhelper.useremployerid)        commaincontact.databind()          public shared function cachedemployeruserlist(byval employerid integer) datatable                dim cachename string = "helper_cachedemployeruserlist_" & cstr(employerid)                dim datalist datatable = nothing                 try                   datalist = httpcontext.current.cache.item(cachename)                catch                 end try                 if datalist nothing                       datalist = core.db.getdata("select [user].id 'id', [user].name + ' ' + [user].surname 'name' employeruser inner join [user] on employeruser.userid = [user].id [user].deleted = 0 , [user].active = 1 , [user].emailverified not null , employeruser.employerid = @employerid order [user].surname, [user].name", core.db.sip("employerid", employerid))         httpcontext.current.cache.insert(cachename, datalist, nothing, dateadd(dateinterval.minute, 1, now), system.web.caching.cache.noslidingexpiration)                 end if                 dim finallist datatable = datalist.copy                 return finallist           end function 

the problem : coding not set default value main contact . want set default value in drop down list main contact. in of cases default value user himself. ideal if current user set default value in drop down list user able change value drop down list if himself not main contact.

how can that.

i can separately determine logged in user.

the coding determine current user (current logged in user can determined via select query fetches data user table.)

public class user   public shared function userfullname(byval user mypeoplebiz.user, optional byval title boolean = true) string          if title              return core.db.getstring("select name title id = @titleid", core.db.sip("titleid", user.titleid)) & " " & user.name & " " & user.surname          else             return user.name & " " & user.surname          end if      end function  end class 

how can set current user set default value in drop down list , give user option of changing value drop down list .

appreciate help.

thanks

set selectedvalue property of dropdown list username string:

commaincontact.selectedvalue = userfullname(arguments)

see https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -