View Full Version : DataGrid Problem

Oct 12th, 2005, 07:31 PM
is it possible to make table like this with DataGrid, what i want to do is to save all quieries in Datatable then bind it to datagrid which will have most of it BoundColumn, the problem is in the seperator in middle, the main topics! :o

Oct 12th, 2005, 08:28 PM
Use Repeater instead of Datagrid if you want a separator.

Oct 13th, 2005, 12:56 AM
Well here's my problem hope to help me if you got time, check this pictures first: http://www11.brinkster.com/cipherk and here's my Code:

Dim Conn As New SqlConnection("DataBase = forum;Integrated Security = SSPI")
Dim ThreadsSql As String = "SELECT COUNT(Threads.ThreadID) AS 'TotalThreads' FROM Threads INNER JOIN Topics ON Threads.TopicID = Topics.TopicID" & _
" GROUP BY Threads.TopicID, Topics.TopicID ORDER BY Topics.TopicID"

Dim PostsSql As String = "SELECT COUNT(dbo.Posts.PostID) AS 'TotalPosts', MAX(dbo.Posts.DatePosted) AS 'Latest' FROM Posts INNER JOIN Topics ON Posts.TopicID = Topics.TopicID" & _
" GROUP BY Posts.TopicID, Topics.TopicID ORDER BY Topics.TopicID"

Dim dadTopics As New SqlDataAdapter
Dim dstTopics As New DataSet

dadTopics.SelectCommand = New SqlCommand(ThreadsSql, Conn)
dadTopics.Fill(dstTopics, "Threads")

dadTopics.SelectCommand = New SqlCommand(PostsSql, Conn)
dadTopics.Fill(dstTopics, "Posts")

'Thread Titles Array()
Dim ThreadTitles(5) As Label
ThreadTitles(0) = jsThreads
ThreadTitles(1) = htcsThreads
ThreadTitles(2) = vbsThreads
ThreadTitles(3) = aspThreads
ThreadTitles(4) = aspnetThreads
ThreadTitles(5) = phpThreads

'Post Titles Array()
Dim PostTitles(5) As Label
PostTitles(0) = jsPosts
PostTitles(1) = htcsPosts
PostTitles(2) = vbsPosts
PostTitles(3) = aspPosts
PostTitles(4) = aspnetPosts
PostTitles(5) = phpPosts

'Last Post Title Array()
Dim LstPostTitles(5) As Label
LstPostTitles(0) = jsLstPost
LstPostTitles(1) = htcsLstPost
LstPostTitles(2) = vbsLstPost
LstPostTitles(3) = asplstPost
LstPostTitles(4) = aspnetLstPost
LstPostTitles(5) = phplstPost

'Last Post Title Array()
Dim ForumCond(5) As System.Web.UI.WebControls.Image
ForumCond(0) = Topic1
ForumCond(1) = Topic2
ForumCond(2) = Topic3
ForumCond(3) = Topic4
ForumCond(4) = Topic5
ForumCond(5) = Topic6

Dim i As Integer
For i = 0 To 5
'Add the total Threads of each topic
ThreadTitles(i).Text = dstTopics.Tables("Threads").Rows(i).Item("TotalThreads")

'Add the total Posts of each topic label
PostTitles(i).Text = (dstTopics.Tables("Posts").Rows(i).Item("TotalPosts") - dstTopics.Tables("Threads").Rows(i).Item("TotalThreads"))

'Add last post of each topic
LstPostTitles(i).Text = dstTopics.Tables("Posts").Rows(i).Item("Latest")

'check if there's new posts by checking if there's posts today
Dim cDay As String = Today
Dim LatestDate As String = dstTopics.Tables("Posts").Rows(i).Item("Latest")
LatestDate = LatestDate.Substring(0, LatestDate.LastIndexOf(Year(Today)) + 4)
If LatestDate = cDay Then
ForumCond(i).ImageUrl = "img/new_posts.gif"
ForumCond(i).ToolTip = "New Posts"
ForumCond(i).ImageUrl = "img/old_posts.gif"
ForumCond(i).ToolTip = "No New Posts"
End If

i have never used this way before, what i want is to use DataGrid or Repeater instead of this way, my idea for now is to use DataTable to save in it both queires then bind it to the control, but i'm still not sure if i have a problem in my database or my query, thanks for help.

Oct 13th, 2005, 02:13 PM
I'm not really sure what your question is...

Do you have VS.NET?

Oct 13th, 2005, 05:10 PM
Sure i have, my question is how to show this query in this table by using datagrid or repeater?! and is my work ir right or is there something wrong!