Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DropDownList in grid

Status
Not open for further replies.

llmclaughlin

Programmer
Aug 20, 2004
140
US
I have a dropdownlist in a gridview, there is no postback on it, but when the value gets changed and when I read the text value on submit for it, it's always the first item in the list.
The code below gets the text value, but always the first item in the dropdown.
Any suggestions how to get on the current index of control.

CType(Me.gvERM.Rows(k).FindControl("ddlFIELD"), DropDownList).Items(CType(Me.gvERM.Rows(k).FindControl("ddlFIELD"), DropDownList).SelectedIndex).Text


Thanks

Louie
 
Without a postback on the ddl, the serverside code will not see the changed value. You either have to add a postback to the ddl or use javascript to get the new index.
 
I think you need to check that the dropdown is not getting rebound after your submit which would actually reset the selectedindex back to 0.

How are you populating the dropdown initially? SqlDataSource? or in your rowdatabound?

Also, been a while since i CType'd, but cant you just do this instead of your longer version above?

CType(Me.gvERM.Rows(k).FindControl("ddlFIELD"), DropDownList).SelectedItem.Text
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top