asp.net - Load DropDownList from Database, then get the Value -
i'm not sure how asp.net works since i'm still new it, coming php background things done post. i'm using vb.net behind code. because main program used here written in vb.net , want keep code portable without compiling library.
my issue follows. have dropdownlist on page. populate data database. seems work fine.
i have button should change clientcode whatever has been selected in dropdownbox. doesn't work. instead index -1.
page code
<%@ page title="" language="vb" autoeventwireup="false" masterpagefile="~/masterpage.master" codebehind="admin.aspx.vb" inherits="wotc_cp.admin" %> <asp:content id="content1" contentplaceholderid="head" runat="server"> </asp:content> <asp:content id="content2" contentplaceholderid="rightbody" runat="server"> <% load_userlist_list() %> <h1 class="sub-header">administration toolbox</h1> <p>if not administrator, please send alert , leave page @ once.</p> <div class="row"> <div class="form-group"> <div class="col-md-4"> <asp:label id="label1" runat="server" text="label">change clientcode;</asp:label> <asp:dropdownlist id="cboclientlist" class="form-control" runat="server" > </asp:dropdownlist> <asp:button id="cmdchangeclientcode" class="btn btn-primary" runat="server" text="change" /> </div> </div> </div>
behind code
public sub load_clientcode_list() if ispostback = false using db new wotcdb dim r = (from t in db.client_main order t.clientcode select t.clientcode).distinct each client in r dim input new listitem input.text = client input.value = client cboclientlist.items.add(input) next end using end if end sub private sub cmdchangeclientcode_click(sender object, e eventargs) handles cmdchangeclientcode.click dim clientcode string = ctype(session("clientcode"), string) dim username string = ctype(session("username"), string) using db new wotcdb dim u = (from t in db.website_users t.username = username).firstordefault if u isnot nothing dim tempid integer = cboclientlist.selectedindex dim tempvalue string = cboclientlist.selectedvalue u.clientcode = cboclientlist.selectedvalue db.savechanges() end if end using end sub
i've tried other answers here on stack, nothing seems work. ideas?
in asp.net dropdown list has 2 key properties want set. datatextfield = display name , datavaluefield = value store db. said, need capture "selectedvalue" if want datavaluefield.
Comments
Post a Comment