I’m not a professional coder. I purchased the “Build Your Own ASP.NET Website” book a few years ago and created a website for my adventure racing business.
The control you want to use here is a GridView. GridView is basically a newer version of the DataGrid.
The being said, when it comes to binding, that is going to be up 2 you. SqlDataReader would be an option, I prefer not to use DataSets. But keep in mind that this is not going to be an easy task for a beginner.
I think it will be easier for you to go the OO route. Create an object(.cs class) for the grid with public properties exposed by getter and setter methods.
eg.
public string teamCountry {get;set;}
public string teamName {get;set;}
etc.
Then you would want a checkpoint object that holds all the info on a check point. eg. Img, stats, etc. Watever you need.
Then in your team object have a generic list of this object public List<CP> teamCheckpointList {get;set;}
Then you load a list of teams from the database, and then load all their checkpoints into the above object list. Then you just but a list of <Teams> to the gridview and use some javascript to make the popup and your done.
This is a very rough guide that will give you a good starting point. So the code is very half, half. So you shouldnt use it as is. I also used the shortcuts for get set, which is also not preferred. and you can write some custom getters to “lazy load” the objects.
But lots of research on this. And ask more specific questions when you get stuck, as this is a very broad question with a lot to it, and it is going to be impossible to help you out completely with this.
Little help. I can’t figure out what is wrong with my syntax. I basically copied it from the ASP.Net book
My Error is:
Line 230: intCPID = dgCheckpoints.DataKeys(e.Item.ItemIndex)
Line 231:
Line 232: strChek = CType(e.Item.Cells(2).Controls(0), TextBox).Text
Line 233:
Line 234: strDate = CType(e.Item.Cells(4).Controls(0), TextBox).Text
I get it when I try to “Update” my DataGrid. Here is my Update coding:
Sub dg_Update(s As Object, e As DataGridCommandEventArgs)
Dim intCPID As Integer
Dim strChek, strDate As String
Dim strCmd As String
intCPID = dgCheckpoints.DataKeys(e.Item.ItemIndex)
strChek = CType(e.Item.Cells(2).Controls(0), TextBox).Text
strDate = CType(e.Item.Cells(4).Controls(0), TextBox).Text
strCmd = "UPDATE tblCPReached SET Chek=@Chek, Date=@Date, Miss=@Miss WHERE CPID=@CPID"
objCmd = New OleDbCommand(strCmd, objConn)
objCmd.Parameters.Add("@Chek", strChek)
objCmd.Parameters.Add("@Date", strDate)
objCmd.Parameters.Add("@CPID", intCPID)
objConn.Open()
objCmd.ExecuteNonQuery()
objConn.Close()
dgCheckpoints.EditItemIndex = -1
BindData2()
End Sub
My Access database table “tblCPReached” has the following columns:
CPID – Primary Key
Race
Chek
Team
Date
Miss
Since I’m also having trouble adding the date and time to my record, I think it might have something to do with my “Date” in a Text string, but I’m not sure how else I should write it.