eexorn eexorn

eexorn eexorn

  • 2k
  • 5
  • 507

Retrieve hardcoded value from dropdownlist on specific gridv

Feb 28 2016 5:09 AM

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
  1. asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false" Width="100%" AllowPaging="true" OnPageIndexChanging="OnPageIndexChanging" PageSize="3" CssClass="Grid"  
  2.   
  3. columns  
  4.   
  5. asp:TemplateField HeaderText="User Type"  
  6.   
  7. ItemTemplate  
  8.   
  9. asp:DropDownList ID="dropdown1field" runat="server"  
  10.   
  11. asp:ListItem Value="0"Select User Type/asp:ListItem  
  12.   
  13. asp:ListItem Value="1">Passenger/asp:ListItem  
  14.   
  15. /asp:DropDownList  
  16.   
  17. /ItemTemplate  
  18.   
  19. /asp:TemplateField  
  20.   
  21. asp:ButtonField ButtonType="Link" CommandName="ClicktoRequest" HeaderText="Click to Request" Text="Click to Request" /  
  22.   
  23. /columns  
  24.   
  25. /asp:GridView  

Code-behind

  1. Protected Sub GridView1_RowCommand(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridview1.RowCommand  
  2.   
  3. If (e.CommandName = "ClicktoRequest"Then  
  4.  Dim index = e.CommandArgument  
  5. Dim ddl = CType(gridview1.Rows(index).FindControl("dropdown1field"),DropDownList)  
  6. Dim dropdown1 = ddl.SelectedItem.Text  
  7. If (dropdown1 = "--Select User Type--"Then  
  8. ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox""alert('Please select a User Type');"True)  
  9. Else  
  10. ClientScript.RegisterStartupScript(Me.GetType(), "AlertMessageBox""alert('Passenger');"True)  
  11. End If  
 
 

Answers (3)