The following code snippets will help you to fill the same values in all dropdonwlist in a form.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then FindDropDown(Page.Controls.GetEnumerator()) End If End Sub Public Sub FindDropDown(ByVal controls As IEnumerator) Dim CtlType As String Dim CtlName As String Dim Ctl As Control While controls.MoveNext() If DirectCast(controls.Current, Control).HasControls() Then FindDropDown(DirectCast(controls.Current, Control).Controls.GetEnumerator()) End If CtlType = DirectCast(controls.Current, Control).GetType().Name Ctl = DirectCast(controls.Current, Control) CtlName = Ctl.ID If CtlType = "DropDownList" Then Call LoadDropDown(Ctl, "No") End If End While End Sub Private Sub LoadDropDown(ByVal DDL As DropDownList, ByVal SelVal As String) Dim InsertList As ListItem With DDL InsertList = New ListItem() InsertList.Text = "Yes" InsertList.Value = "Y" .Items.Add(InsertList) InsertList = New ListItem() InsertList.Text = "No" InsertList.Value = "N" .Items.Add(InsertList) If SelVal = "No" Then .SelectedValue = "N" ElseIf SelVal = "Yes" Then .SelectedValue = "Y" End If End With End Sub
Regards, Kulanthaivelu.V
|
No responses found. Be the first to respond and make money from revenue sharing program.
|