[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 621
  • Last Modified:

Capturing the selected index of a dropdown in the gridview

I have a dropdown inside of a gridview.  The user will select an item from the dropdown and click a link button (also inside the gridview).  

I am capturing the click event in the gridview's  RowCommand, but I also need to capture the value of the dropdown from the clicked row to pass to the next page.  

I tried this from the Rowcommand event, but I am getting an error.  

Dim ddl As DropDownList = TryCast(e.Row.FindControl("ddlCadence"), DropDownList)

Can someone help, please.

Thank you
0
sherbug1015
Asked:
sherbug1015
1 Solution
 
Element1910Commented:
What error are you getting??

You could try this in the meantime...add a OnSelectedIndexChanged event to your dropdownlist:
OnSelectedIndexChanged="ddlCadence_SelectedIndexChanged"

Open in new window

Then to capture the selected value:
Protected Sub ddlCadence_SelectedIndexChanged(sender As Object, e As EventArgs)
	Dim gv1 As GridViewRow = DirectCast(DirectCast(sender, Control).NamingContainer, GridViewRow)
	Dim ddl As DropDownList = DirectCast(gv1.FindControl("ddlCadence"), DropDownList)
	TextBox1.Text = ddl.SelectedItem.Value
End Sub

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now