if Not ispostback ใน pageload มันก็จะดึงทีเดียว แต่อยากทราบว่าในดาต้ากริด จะใส่ตรงไหนให้มันไม่ดึงค่าซ้ำอะค่ะ
โค้ด
Code (VB.NET)
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = UI.WebControls.ListItemType.Item Or e.Item.ItemType = UI.WebControls.ListItemType.AlternatingItem Then
Dim DDlCom As System.Web.UI.WebControls.DropDownList
DDlCom = e.Item.FindControl("DdlCom")
Dim Myda1 As New SqlDataAdapter("Select Code From Tl_ComponentCode order by code", Conn)
Myda1.Fill(Ds, "datacom")
If Ds.Tables("datacom").Rows.Count > 0 Then
With DDlCom
.DataSource = Ds.Tables("datacom")
.DataTextField = "Code"
.DataValueField = "Code"
.DataBind()
End With
End If
Dim DdlDmg As System.Web.UI.WebControls.DropDownList
DdlDmg = e.Item.FindControl("DdlDmg")
Dim Myda2 As New SqlDataAdapter("Select Code_Da From Tl_DamageCode order by Code_Da", Conn)
Myda2.Fill(Ds, "dataDMG")
If Ds.Tables("dataDMG").Rows.Count > 0 Then
With DdlDmg
.DataSource = Ds.Tables("dataDMG")
.DataTextField = "Code_Da"
.DataValueField = "Code_Da"
.DataBind()
End With
End If
Dim DdlRepair As System.Web.UI.WebControls.DropDownList
DdlRepair = e.Item.FindControl("DdlRepair")
Dim Myda3 As New SqlDataAdapter("Select Code_Repair From Tl_RepairCode order by Code_Repair", Conn)
Myda3.Fill(Ds, "dataRep")
If Ds.Tables("dataRep").Rows.Count > 0 Then
With DdlRepair
.DataSource = Ds.Tables("dataRep")
.DataTextField = "Code_Repair"
.DataValueField = "Code_Repair"
.DataBind()
End With
End If
End If
End Sub
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), VB.NET