Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: Databinding a dropdownlist in asp.net  (Read 722 times)
0 Members and 1 Guest are viewing this topic.
Arkie
Javaforums.net Admin
Senior Member
*

Reputation: 16
Developer @ Javaforums.net
Offline Offline
Posts: 2593
Referrals: 13

WWW Awards
« on: July 15, 2009, 03:27:22 PM »

You can populate a dropdownlist in asp.net .NET framework 2.0 this way:


Code
GeSHi (csharp):
  1. Dictionary<int, string> getData= v.returnDictionaryMethod();
  2.  
  3.        DropDownListData.DataTextField = "Value";
  4.        DropDownListData.DataValueField = "Key";
  5.        DropDownListData.DataSource = getData;
  6.        DropDownListData.DataBind();
  7.  
  8. //The returnDictionary method looks like this:
  9.  
  10. public Dictionary<int, string> returnDictionary ()
  11.        {
  12.   Dictionary<int, string> d = new Dictionary<int, string>();
  13. //fill the dictionary with data from an sql database  or another source here
  14.          return d;
  15. }
  16.  
Created by GeSHI 1.0.7.20

Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here