dropdown binding question [Resolved]

Posted by Surajemo under ASP.NET on 3/24/2012 | Points: 10 | Views : 1166 | Status : [Member] | Replies : 6
i wanted to ask when we want to fill dropdownbox with value from the database
we write
like this
query "select id , Name from emloyee"
dtTable ---> DataTable;

DropDownList1.DataSource = dtTable;

DropDownList1.DataTextField = "Name";

DropDownList1.DataValueField= "Id";

DropDownList.DataBind();

in the code if we dont write " DropDownList1.DataValueField= "Id";" still the dropdown is getting filled with all the id so y do we write that code --> DropDownList1.DataValueField= "Id";<--
OR VICEVERSA

if we dont write --->DropDownList1.DataTextField = "Name";<---- and still the dropdown is getting filled with all the id so y do we write that code --> DropDownList1.DataValueField= "Id";<--
what is the importanceof that
can some please tell me




Responses

Posted by: Avdesh on: 3/24/2012 [Member] Starter | Points: 50

Up
0
Down

Resolved
DropDownList1.DataTextField = "Name";/////Key
DropDownList1.DataValueField= "Id"; /////value
Both worked as key and value basis.if you write
DropDownList1.DataTextField = "Name" ;
DropDownList1.DataValueField= "Id";
it shows text at front end but at backend it saves both values
Thanks And Regards
Avdesh

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

Posted by: Sksamantaray on: 3/24/2012 [Member] Silver | Points: 50

Up
0
Down

Resolved
ID field is unique,Text Field may have duplicate values.
Lets say you are showing students names , there are few students where student name is same but their Rollno is unique , user should see the student name but taking the Rollno the database needs to be queried.
Value field helps in this situation.

Thanks,
Sanjay

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

Posted by: Surajemo on: 3/24/2012 [Member] Starter | Points: 25

Up
0
Down
can u please elaborate this little bit more on Datatextfield and Datavalue field please :)

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

Posted by: Surajemo on: 3/24/2012 [Member] Starter | Points: 25

Up
0
Down
can u please elaborate this little bit more on Datatextfield and Datavalue field please :)

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

Posted by: Surajemo on: 3/25/2012 [Member] Starter | Points: 25

Up
0
Down
Sksamantaray sir Thank u :)

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

Posted by: perfectchourasia-9163 on: 4/3/2012 [Member] Starter | Points: 25

Up
0
Down
http://sandeep-chourasia.blogspot.in/2011/08/populating-dropdownlist.html

ER sandeep chourasia
sandeepchrs@yahoo.com (on facebook)
http://www.aspnetcodes.com/

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

Login to post response