Drop Down Under Repeater Using VB.NET

Bind Drop Down with Reapter:

 <asp:Repeater runat="server" ID="rp_DropDown" OnItemDataBound="rp_DropDown_ItemDataBound">
   <HeaderTemplate>
        <div>
                DropDown
        </div> 
   </HeaderTemplate>
   <ItemTemplate>
        <div>
              <asp:DropDownList ID="DropDown1" runat="server"
               OnSelectedIndexChanged="DropDown1Changed" AutoPostBack="true">
                </asp:DropDownList>
         </div>                               
   </ItemTemplate>

 </asp:Repeater>

Bind Data In Drop Down:

Dim DropDown1 As DropDownList = CType(e.Item.FindControl("DropDown1"), DropDownList)


  Dim DataList As IList(Of String) = New List(Of String)
  DataList.Insert(1,"ABC")
  DataList.Insert(2,"DEF")
  DataList.Insert(3,"GHI")
  DropDownList .DataSource = DataList 
  DropDownList .DataTextField = "Name"
  DropDownList .DataValueField = "Key"
  DropDownList .DataBind()



Drop Down IndexChanged Event For a particular Row:


  Protected Sub DropDown1Changed(ByVal sender As Object, ByVal e As EventArgs)

        For Each rpItem As RepeaterItem In rp_DropDown.Items

            Dim DropDown2 As DropDownList = CType(rpItem.FindControl("DropDown1"), DropDownList)
                     If (DropDown2 .GetHashCode = sender.GetHashCode) Then

'Code for that row in which drop down index changed
                          End If
        Next
    End Sub



Comments

Popular posts from this blog

C# Copy files from one server to another

Export SharePoint Online Group Users to Excel using Powershell