回答編集履歴

2

コードま間違いの修正

2016/09/12 00:00

投稿

twck
twck

スコア314

test CHANGED
@@ -44,15 +44,15 @@
44
44
 
45
45
  'FormView1の中から各コントロールを探して値をセットする
46
46
 
47
- DirectCast(FormView1.FindControl("DropDownList1"), DropDownList).SelectedValue = "はい"
47
+ DirectCast(FormView1.FindControl("DropDownList1"), DropDownList).SelectedValue = reader("result1").ToString
48
48
 
49
- DirectCast(FormView1.FindControl("DropDownList2"), DropDownList).SelectedValue = "いいえ"
49
+ DirectCast(FormView1.FindControl("DropDownList2"), DropDownList).SelectedValue = reader("result2").ToString
50
50
 
51
- DirectCast(FormView1.FindControl("DropDownList3"), DropDownList).SelectedValue = "はい"
51
+ DirectCast(FormView1.FindControl("DropDownList3"), DropDownList).SelectedValue = reader("result3").ToString
52
52
 
53
- DirectCast(FormView1.FindControl("DropDownList4"), DropDownList).SelectedValue = "はい"
53
+ DirectCast(FormView1.FindControl("DropDownList4"), DropDownList).SelectedValue = reader("result4").ToString
54
54
 
55
- DirectCast(FormView1.FindControl("DropDownList5"), DropDownList).SelectedValue = "未回答"
55
+ DirectCast(FormView1.FindControl("DropDownList5"), DropDownList).SelectedValue = reader("result5").ToString
56
56
 
57
57
  End If
58
58
 

1

コードの追加

2016/09/12 00:00

投稿

twck
twck

スコア314

test CHANGED
@@ -17,6 +17,50 @@
17
17
  ```VB
18
18
 
19
19
  Private Sub FormView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles FormView1.DataBound
20
+
21
+
22
+
23
+ '新規登録モードのときのみ
24
+
25
+ If FormView1.CurrentMode = FormViewMode.Insert Then
26
+
27
+
28
+
29
+ '初期値用のレコードを読み込んで各コントロールにセットする
30
+
31
+ Using db As New System.Data.SqlClient.SqlConnection(接続文字列)
32
+
33
+ db.Open()
34
+
35
+ Dim cmd = db.CreateCommand()
36
+
37
+ cmd.CommandText = "SELECT * FROM テーブル名 WHERE ID = 初期値のレコードのキー"
38
+
39
+ Using reader = cmd.ExecuteReader
40
+
41
+ If reader.Read Then
42
+
43
+
44
+
45
+ 'FormView1の中から各コントロールを探して値をセットする
46
+
47
+ DirectCast(FormView1.FindControl("DropDownList1"), DropDownList).SelectedValue = "はい"
48
+
49
+ DirectCast(FormView1.FindControl("DropDownList2"), DropDownList).SelectedValue = "いいえ"
50
+
51
+ DirectCast(FormView1.FindControl("DropDownList3"), DropDownList).SelectedValue = "はい"
52
+
53
+ DirectCast(FormView1.FindControl("DropDownList4"), DropDownList).SelectedValue = "はい"
54
+
55
+ DirectCast(FormView1.FindControl("DropDownList5"), DropDownList).SelectedValue = "未回答"
56
+
57
+ End If
58
+
59
+ End Using
60
+
61
+ End Using
62
+
63
+ End If
20
64
 
21
65
 
22
66