Would need your help on this, i am trying to retrieve a list item value onselected from a dropdownlist on a specific gridview row.
The problem is no matter what is selected, it will always return the first result and not go to the else statement.
ASPX code
- asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false" Width="100%" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging" PageSize="3" CssClass="Grid"
-
- columns
-
- asp:TemplateField HeaderText="User Type"
-
- ItemTemplate
-
- asp:DropDownList ID="dropdown1field" runat="server"
-
- asp:ListItem Value="0"Select User Type/asp:ListItem
-
- asp:ListItem Value="1">Passenger/asp:ListItem
-
- /asp:DropDownList
-
- /ItemTemplate
-
- /asp:TemplateField
-
- asp:ButtonField ButtonType="Link" CommandName="ClicktoRequest" HeaderText="Click to Request" Text="Click to Request" /
-
- /columns
-
- /asp:GridView
Code-behind
- Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridview1.RowCommand
-
- If (e.CommandName = "ClicktoRequest") Then
- Dim index = e.CommandArgument
- Dim ddl = CType(gridview1.Rows(index).FindControl("dropdown1field"),DropDownList)
- Dim dropdown1 = ddl.SelectedItem.Text
- If (dropdown1 = "--Select User Type--") Then
- ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('Please select a User Type');", True)
- Else
- ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox", "alert('Passenger');", True)
- End If