Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with DataGrid 1

Status
Not open for further replies.

gpalmer711

IS-IT--Management
May 11, 2001
2,445
GB
I apologise is this is a stupid question but i've been googling for ages and cannot seem to get my head around this, if someone could point me in the right direction I would really appreciate it.

Here is the situation;

I am currently developing a Leaderboard Website for a Xbox site as a free of charge project in my spare time. I have everything working apart from this one part, adding the scores for each player.

Each League is split into Seasons, then Weeks, then Rounds also each league may have just individual players or teams with players within them.

When it comes to entering the players scores this will be done on a weekly basis, and all rounds for that week need to be displayed so the league organiser can enter the scores in an easy a way as possible.

I figured a DataGrid would be the best beast for the job. Now as I do not know how many teams there will be and likewise how many players there will be, the datagrid(s) need to be created dynamically. Up to this point i'm fine, I can create a different datagrid for each team, and in each datagrid can add a column for the players name and a column for each round.

However what I cannot seem to figure out is how to make each row editable.

Here is the code that I am using to create the datagrid(s)
Code:
Dim myRow As DataRow
            For Each myRow In DS.Tables.Item(0).Rows
                Dim myDataGrid As DataGrid
                myDataGrid = New DataGrid
                myDataGrid.AutoGenerateColumns = True
                myDataGrid.DataSource = CreateDataSource(myRow.Item("season_id"), myRow.Item("ID"))
                myDataGrid.Enabled = True
                myDataGrid.DataBind()
                pnlPlayers.Controls.Add(myDataGrid)
            Next

Here is the code that creates the datasource

Code:
    Function CreateDataSource(ByVal intSeason As Integer, ByVal intTeam As Integer) As DataTable
        Dim dt As New DataTable
        Dim dr As DataRow
        dt.Columns.Add(New DataColumn("Players", GetType(String)))
        Dim DS2 As New DataSet
        Dim strConnString As String = ConfigurationManager.ConnectionStrings("XBLA").ConnectionString
        Dim objSQLAdapter2 As New SqlDataAdapter("SELECT * FROM xbla_rounds WHERE week_id = " & selWeek.SelectedValue, strConnString)
        objSQLAdapter2.Fill(DS2)
        Dim intRounds As Integer
        For intRounds = 0 To DS2.Tables(0).Rows.Count - 1
            dt.Columns.Add(New DataColumn(DS2.Tables(0).Rows(intRounds).Item("round_name").ToString, GetType(Int32)))
        Next
        'dt.Columns.Add(New DataColumn("IntegerValue", GetType(Int32)))
        Dim DS1 As New DataSet
        Dim objSQLAdapter As New SqlDataAdapter("SELECT [xblaleagues].[dbo].[xbla_users].[gamertag] FROM [xblaleagues].[dbo].[xbla_users], [xblaleagues].[dbo].[xbla_players] WHERE [xblaleagues].[dbo].[xbla_users].[ID] = [xblaleagues].[dbo].[xbla_players].[ID] AND [xblaleagues].[dbo].[xbla_players].[team_id] = " & intTeam.ToString & " AND [xblaleagues].[dbo].[xbla_players].[season_id] = " & intSeason.ToString, strConnString)
        objSQLAdapter.Fill(DS1)
        If DS1.Tables(0).Rows.Count <> 0 Then
            Dim i As Integer
            For i = 0 To DS1.Tables(0).Rows.Count - 1
                dr = dt.NewRow
                dr(0) = DS1.Tables(0).Rows(i).Item("gamertag").ToString
                dt.Rows.Add(dr)
            Next
            DS1.Dispose()
            objSQLAdapter.Dispose()
        End If
        Return dt
    End Function

Thanks in advance for any help you can give.

Greg Palmer
 
Here is a image of what the output looks like at the moment

 
Thanks for that - it certainly pointed me in the right direction of TemplateColumns and although it worked in the sense of adding the textboxes that I needed.

I realised that the work involved in trying to get all the data from a indetermined number of datagrids was going to be a really Pain in the bottom.

So I've decided to go for a DataGrid that is added at design time and then at runtime i'll populate it with the players and add an extra column for the team name.

Thanks again

Greg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top