I have a drop down list inside a gridview and i am filling values dynamically and how can i get the ID of the first item in the DDL without selecting??
It is not about what caused you to fall flat on your back that defines you; it is what you do to get back up on your feet.
while binding itself, you can bind ID values to DataValueField of DDL and then you can retrieve it by using FindControl and find the DDL first, then you can get the first item or item of your interest by DDL.ITems.FindByValue() or FindByText()....
.net_junkie
Member
297 Points
825 Posts
DDL item ID without selection
Oct 28, 2012 06:20 AM|LINK
I have a drop down list inside a gridview and i am filling values dynamically and how can i get the ID of the first item in the DDL without selecting??
oned_gk
All-Star
35728 Points
7296 Posts
Re: DDL item ID without selection
Oct 28, 2012 06:27 AM|LINK
Suwandi - Non Graduate Programmer
.net_junkie
Member
297 Points
825 Posts
Re: DDL item ID without selection
Oct 28, 2012 06:30 AM|LINK
Based on the id i have to fetch the value from the table.
oned_gk
All-Star
35728 Points
7296 Posts
Re: DDL item ID without selection
Oct 28, 2012 06:39 AM|LINK
Suwandi - Non Graduate Programmer
ramiramilu
All-Star
97713 Points
14461 Posts
Re: DDL item ID without selection
Oct 28, 2012 09:27 AM|LINK
while binding itself, you can bind ID values to DataValueField of DDL and then you can retrieve it by using FindControl and find the DDL first, then you can get the first item or item of your interest by DDL.ITems.FindByValue() or FindByText()....
Thanks,
JumpStart
.net_junkie
Member
297 Points
825 Posts
Re: DDL item ID without selection
Oct 28, 2012 05:12 PM|LINK
Ya i am binding the ID to the DataValuefield of the DDL but how can get the ID of first item?? how can can you provide some code??
DDL.ITems.FindByValue("what should i write here")??
oned_gk
All-Star
35728 Points
7296 Posts
Re: DDL item ID without selection
Oct 29, 2012 03:33 AM|LINK
selectedvalue='<%# Bind ("yourgvfieldname") %>'
Suwandi - Non Graduate Programmer
.net_junkie
Member
297 Points
825 Posts
Re: DDL item ID without selection
Oct 29, 2012 04:38 AM|LINK
Where i have to bind this??
MetalAsp.Net
All-Star
112702 Points
18360 Posts
Moderator
Re: Fetch the ID of items inside a DDL
Oct 29, 2012 04:53 AM|LINK
santosh.jagd...
Star
7625 Points
1454 Posts
Re: Fetch the ID of items inside a DDL
Oct 29, 2012 04:57 AM|LINK
you can use DataValueField property of DDL.
MCP