gpalmer711
IS-IT--Management
Hi All,
I'm sure this is something really simple but I am about to pull my hair out
over this.
ASP.NET - VB as Language
I have a DataGrid added to a form at design time.
At runtime I want to retrieve some data from a database and then add a few
columns with either textboxes or drop down boxes. This is no problem and I
am currently using the code below to do this.
However what I want to do is get the values from those controls when a
button is pressed at the bottom of the form. I don't seem able to reference
the controls at all and when the form is posted back, on the button press,
the controls disappear.
Any point in the right direction would be greatly appreciated.
Regards
Greg Palmer
Click event on button
I'm sure this is something really simple but I am about to pull my hair out
over this.
ASP.NET - VB as Language
I have a DataGrid added to a form at design time.
At runtime I want to retrieve some data from a database and then add a few
columns with either textboxes or drop down boxes. This is no problem and I
am currently using the code below to do this.
However what I want to do is get the values from those controls when a
button is pressed at the bottom of the form. I don't seem able to reference
the controls at all and when the form is posted back, on the button press,
the controls disappear.
Any point in the right direction would be greatly appreciated.
Regards
Greg Palmer
Code:
Public Sub DisplayPlayers()
Dim mySQL As String = ""
Dim DS As New DataSet
Dim strConnString As String =
ConfigurationManager.ConnectionStrings("XBLA").ConnectionString
Dim objSQLAdapter As New SqlDataAdapter("SELECT * FROM [xbla_teams] WHERE
season_ID = " & selSeason.SelectedValue.ToString, strConnString)
objSQLAdapter.Fill(DS, "[xbla_teams]")
If DS.Tables(0).Rows.Count > 0 Then
mySQL = mySQL & "sql goes here "
Dim myRow As Integer
For myRow = 0 To DS.Tables(0).Rows.Count - 1
If myRow = 0 Then
mySQL = mySQL & "sql goes here "
Else
mySQL = mySQL & "sql goes here "
End If
Next
mySQL = mySQL & "sql goes here
Else
mySQL = mySQL & "SELECT [xblaleagues].[dbo].[xbla_users].[gamertag] as
GamerTAG "
mySQL = mySQL & "sql goes here "
End If
Dim DS1 As New DataSet
Dim objSQLAdapter1 As New SqlDataAdapter(mySQL, strConnString)
objSQLAdapter1.Fill(DS1, "[xbla_players]")
playersGrid.DataSource = DS1.Tables(0)
'code for each round
Dim DS2 As New DataSet
Dim objSQLAdapter2 As New SqlDataAdapter("sql goes here ", strConnString)
objSQLAdapter2.Fill(DS2)
Dim intRounds As Integer
For intRounds = 0 To DS2.Tables(0).Rows.Count - 1
Dim tc1 As New TemplateField()
If DS2.Tables(0).Rows(intRounds).Item("round_type").ToString = "Points" Then
tc1.ItemTemplate = Page.LoadTemplate("pointsTemplate.ascx")
tc1.EditItemTemplate = Page.LoadTemplate("pointsTemplate.ascx")
ElseIf DS2.Tables(0).Rows(intRounds).Item("round_type").ToString =
"Position" Then
tc1.ItemTemplate = Page.LoadTemplate("positionTemplate.ascx")
tc1.EditItemTemplate = Page.LoadTemplate("positionTemplate.ascx")
End If
tc1.HeaderText = DS2.Tables(0).Rows(intRounds).Item("round_name").ToString
playersGrid.Columns.Add(tc1)
Next
playersGrid.DataBind()
DS.Dispose()
objSQLAdapter.Dispose()
End Sub
Code:
Protected Sub cmdAddPoints_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles cmdAddPoints.Click
Dim strMsg As String = ""
strMsg = "Number of rows = " & playersGrid.Rows.Count.ToString & vbCrLf
strMsg = strMsg & "Number of Columns = " &
playersGrid.Columns.Count.ToString & vbCrLf
strMsg = strMsg & "Has Controls = " &
playersGrid.Rows(0).Cells(0).HasControls.ToString '----This always comes out
as false
MsgBox(strMsg)
End Sub