N
nicolas.neuilly
Basically, I have a DropDownList control on a page that inputs a string
into a database. The user can later go back to the same page in
"update" mode to make further changes. So what I need to do is pull the
value back out of the database and pass it back to the control so that
value is pre-selected in the dropdown list. It works out except when
the field is a foreign key of another table.
Here is the code. It works out for the textbox and the first ddl, but
not for the second dll as field3 is in table 2:
Sub Bind()
Dim dr As SqlDataReader
Dim sql As String = "Select * from TABLE1 T1,TABLE2 T2 where T1.KEY2 =
T2.KEY2 AND KEY1 = " & ItemID
dr = SQLHelper.ExecuteReader(ConnectionString,
System.Data.CommandType.Text, sql)
If dr.HasRows Then
dr.Read()
TextBox1.Text = dr("FIELD1").ToString
DDL1.SelectedIndex =
DDL1.Items.IndexOf(DDL1.Items.FindByText(dr("FIELD2").ToString))
DDL2.SelectedIndex =
DDL2.Items.IndexOf(DDL2.Items.FindByText(dr("FIELD3").ToString))
DataBind()
end if
dr.Close
End Sub
into a database. The user can later go back to the same page in
"update" mode to make further changes. So what I need to do is pull the
value back out of the database and pass it back to the control so that
value is pre-selected in the dropdown list. It works out except when
the field is a foreign key of another table.
Here is the code. It works out for the textbox and the first ddl, but
not for the second dll as field3 is in table 2:
Sub Bind()
Dim dr As SqlDataReader
Dim sql As String = "Select * from TABLE1 T1,TABLE2 T2 where T1.KEY2 =
T2.KEY2 AND KEY1 = " & ItemID
dr = SQLHelper.ExecuteReader(ConnectionString,
System.Data.CommandType.Text, sql)
If dr.HasRows Then
dr.Read()
TextBox1.Text = dr("FIELD1").ToString
DDL1.SelectedIndex =
DDL1.Items.IndexOf(DDL1.Items.FindByText(dr("FIELD2").ToString))
DDL2.SelectedIndex =
DDL2.Items.IndexOf(DDL2.Items.FindByText(dr("FIELD3").ToString))
DataBind()
end if
dr.Close
End Sub