I have a VB.net web form that consists of a dropdownlist called ddlAuthor, a textbox called txtYear, a search button, and an asp.net gridview. After user selects the author's name in the ddlAuthor dropdownlist box, type in the year in the txtYear textbox, and click the search button, a gridview called AuthorGridView will show up.
The gridview consists of Author , Book Title, Year of Publication, and Coauthors columns. The left most column in each row of the gridview contains the Edit link followed by other columns. The Edit link is just a regular HTML anchor element and when it's clicked I would like to set the selected value of ddlAuthor to the Author name in the same row as the clicked Edit link.
I did some research on setting the value of a dropdown using jQuery and found many posts suggesting people to use jQuery val() function. I tried it but it didn't work.
Because I'm using asp.net controls their IDs will be altered when the page is rendered in the browser and I have to use a special code to grab the ID of each control to be used by jQuery.
When I click the Edit link in the gridview, I was able to grab the Author name in the column next to it using the jQuery script below.
The alert shows the name of the Author which is in the column next to the clicked Edit link but I was not able to set the selected value of ddlAuthor dropdown using the line below.