drop down menu - How can I change the dropdownlist's options? -


i'm newbie in asp.net i'm hoping give me on dropdownlist bound table.

here's scenario:

i have table account fields userid, username , type. type field contains 3 items: 's', 'a', , 'u'. each user has own type. have dropdownlist named 'ddltype'

bound on account table. however, want options of dropdownlist displayed 'stakeholder', 'approver', , 'user' instead of displaying letters/initials only. since not prefer making changes in database, how can change options through code behind?

here's code:

public void bindcontrols(int selecteduserid) { datatable dtaccount = null;

try {     dtaccount = logbal.getaccountdetails(selecteduserid);      if (dtaccount.rows.count > 0)     {         lbluserid.text = dtaccount.rows[0]["userid"].tostring();         txtusername.text = dtaccount.rows[0]["username"].tostring();         ddltype.selectedvalue = dtaccount.rows[0]["type"].tostring();     } } catch (exception ex) {     throw ex; } {     dtaccount.dispose(); } 

}

any guys appreciated. in advanced! :d

you can bind dropdownlist in codebehind.

get data "type" array. make array 2 dimentional , assign values it.

after having data array looks this, string[,] types = { { "stakeholder", "s" }, { "approver", "a" }, { "user", "u" } };

now assign values dropdown, int rows = types.getupperbound(0);
int columns = types.getupperbound(1);
ddltype.items.clear(); (int currentrow = 0; currentrow <= rows; currentrow++)
{
listitem li = new listitem();
(int currentcolumn = 0; currentcolumn <= columns; currentcolumn++)
{
if (currentcolumn == 0)
{
li.text = types[currentrow, currentcolumn];
}
else
{
li.value = types[currentrow, currentcolumn];
}
}
ddltype.items.add(li);
}

i haven't tested work.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -