In my web form, my drop down list already have the code to load the data selection. Now I want to add an auto fill function based on the query string in URL.
Private Sub FillLine() '1st dropdown
'1. Load intial selection into drop down list (OK)
'----------------------------------------------------------------------------------------------------
Dim dt As New DataTable
Dim strSql = "select distinct level1_id, [LCODE1]+ ' | '+[LNAME1] as [LCODE1]" _
& " FROM [SQLIOT].[dbo].[ZVIEW_MCM_LEVEL_LOOKUP]"
Using conn As New SqlConnection(ConStr),
cmd As New SqlCommand(strSql, conn)
conn.Open()
dt.Load(cmd.ExecuteReader)
End Using
If dt.Rows.Count > 0 Then
line.DataSource = dt
line.DataTextField = "LCODE1"
line.DataValueField = "level1_id"
line.DataBind()
line.Items.Insert(0, "")
End If
'----------------------------------------------------------------------------------------------------
'2. Pick out the value in drop down list based on URL query string (NG)
'----------------------------------------------------------------------------------------------------
Dim LID As String = Request.QueryString("LID")
If LID <> Nothing Then
LID3.Text = LID
If Not IsPostBack() Then
Dim cmdLID As New SqlCommand("select distinct [LCODE1]+ ' | '+[LNAME1] as [LCODE1] " _
& "FROM [SQLIOT].[dbo].[ZVIEW_MCM_LEVEL_LOOKUP] " _
& "where [LEVEL3_ID] = '" & LID3.Text & "'", conn)
conn.Open()
Dim rdr As SqlDataReader = cmdLID.ExecuteReader
While rdr.Read
line.Text = rdr("LCODE1")
End While
conn.Close()
End If
End If
'----------------------------------------------------------------------------------------------------
End Sub
Protected Sub line_selectedindexchanged(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim level1_ID As Integer = Convert.ToInt32(line.SelectedValue.ToString())
Dim value As Integer = Integer.Parse(level1_ID)
FillProcess(level1_ID)
Catch ex As Exception
Console.WriteLine(ex)
End Try
'FillProcess(level1_ID)
End Sub
During testing, part 1 of my code is fine. However, in part 2, every time I input the LID
query string in my URL and refresh the page, the value won't show in my drop down list.
What may be the issue here?