bind a combobox by userID

Posted by Jopito under ASP.NET on 1/24/2014 | Points: 10 | Views : 1270 | Status : [Member] | Replies : 1
Hello ,i have a combobox StudentName which should show the student Name.His studentId is available but i need to bind the combobox to show the name of that student by his id.Am using membership

here is the sample code
 MembershipUser student = Membership.GetUser(Page.User.Identity.Name);
Guid id =new Guid(student.ProviderUserKey.ToString());

int StudentId = StudentsList.FetchStudentId((id));


This give me the student Id but i need to have his name too.It changes everytime one logs in since studentName has other users registered under him so if those students registered by his name have logged in.the combobobox is bound to the Student who registered them

Mark as answer if satisfied


Responses

Posted by: kgovindarao523-21772 on: 1/24/2014 [Member] [MVP] Bronze | Points: 25

Up
0
Down
Hi,

Try this code to bind Combo box.
Dictionary<int, string> choices = new Dictionary<int, string>();
choices.Add(1, "Jupito");
choices.Add(2, "John");
choices.Add(3, "Michel");
choices.Add(4, "Wills");
//Bind your values to dictionary dynamically if you want.
cmbPaidBy.DataSource = choices;
cmbPaidBy.DisplayMember = "Value";
cmbPaidBy.ValueMember = "Key";
cmbPaidBy.DataBind();


Thank you,
Govind

Jopito, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response