G
Guest
I have two tables, tblPost - (Cols PostID, TopicID, UserID, Question, PostMsg
and PostDT) and tblTopic - (Cols TopicID, Topic). I am trying to get
tblPost.Question and tblPost.PostDT into DataGrid1 when the DropDownList1
(which consists of Topic) is clicked.
I have the following code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim cnn as New SqlClient.SqlConnection("data source=SILVER; initial
catalog=RidingForEveryone; integrated security=SSPI;")
Dim da as SqlDataAdapter = New SqlDataAdapter
Dim ds as DataSet = New DataSet()
da.SelectCommand = New SqlCommand("spFillTopicddl")
da.SelectCommand.Connection = cnn
da.SelectCommand.CommandType = CommandType.StoredProcedure
da.Fill(ds, "tTopic")
DropDownList1.DataSource = ds
DropDownList1.DataMember = "tTopic"
DropDownList1.DataTextField = "Topic"
DropDownList1.DataBind()
End If
End Sub
Sub FillPost()
Dim cnn as New SqlClient.SqlConnection("data source=SILVER; initial
catalog=RidingForEveryone; integrated security=SSPI;")
Dim da as SqlDataAdapter = New SqlDataAdapter
Dim myCommand as SqlCommand = New SqlCommand("Select Question, PostDT From
tblPost inner join tblTopic on tblTopic.TopicID = tblPost.TopicID Where
tblTopic.TopicID=" & DropDownList1.SelectedIndex.ToString, cnn)
Dim ds as New DataSet()
da.SelectCommand = myCommand
da.Fill(ds, "tPost")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "tPost"
DataGrid1.DataBind()
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
FillPost()
End Sub
The DropDownList is filled when the page is loaded. When I click on an
item, however, the DataGrid is displayed and nothing is in it, no matter what
item I select in the DropDownList. Visual Studio doesn't complain about a
thing . . . it just merely returns nothing.
Any help anyone can give me will be greatly appreciated!
and PostDT) and tblTopic - (Cols TopicID, Topic). I am trying to get
tblPost.Question and tblPost.PostDT into DataGrid1 when the DropDownList1
(which consists of Topic) is clicked.
I have the following code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim cnn as New SqlClient.SqlConnection("data source=SILVER; initial
catalog=RidingForEveryone; integrated security=SSPI;")
Dim da as SqlDataAdapter = New SqlDataAdapter
Dim ds as DataSet = New DataSet()
da.SelectCommand = New SqlCommand("spFillTopicddl")
da.SelectCommand.Connection = cnn
da.SelectCommand.CommandType = CommandType.StoredProcedure
da.Fill(ds, "tTopic")
DropDownList1.DataSource = ds
DropDownList1.DataMember = "tTopic"
DropDownList1.DataTextField = "Topic"
DropDownList1.DataBind()
End If
End Sub
Sub FillPost()
Dim cnn as New SqlClient.SqlConnection("data source=SILVER; initial
catalog=RidingForEveryone; integrated security=SSPI;")
Dim da as SqlDataAdapter = New SqlDataAdapter
Dim myCommand as SqlCommand = New SqlCommand("Select Question, PostDT From
tblPost inner join tblTopic on tblTopic.TopicID = tblPost.TopicID Where
tblTopic.TopicID=" & DropDownList1.SelectedIndex.ToString, cnn)
Dim ds as New DataSet()
da.SelectCommand = myCommand
da.Fill(ds, "tPost")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "tPost"
DataGrid1.DataBind()
End Sub
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
FillPost()
End Sub
The DropDownList is filled when the page is loaded. When I click on an
item, however, the DataGrid is displayed and nothing is in it, no matter what
item I select in the DropDownList. Visual Studio doesn't complain about a
thing . . . it just merely returns nothing.
Any help anyone can give me will be greatly appreciated!