song2siren
Programmer
Hello
I'm having difficulty displaying a particular image button in a DataList depending on the value of a field in my SQL database. I'm using the following to execute a stored procedure and retrieve a dataset:
Sub getResultsbySubject(Source as Object, e as EventArgs)
myDataAdapter = New SqlDataAdapter("Pubs_SearchbySubject", myConnection)
myDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
myDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Search", SqlDbType.NVarChar, 255))
myDataAdapter.SelectCommand.Parameters("@Search").Value = frmSubjects.selectedvalue
resultDS = New DataSet()
myDataAdapter.Fill(resultDS, "Results")
dlResults.DataSource = resultDS.Tables("Results").DefaultView
Session("resultDSDataTable") = resultDS.Tables("Results")
BindDataList
myDataAdapter.Dispose()
myConnection.Close
End Sub
Sub BindDataList
dlResults.DataBind()
' Display a message if no results are found
If dlResults.Items.Count = 0 Then
ErrorMsg.Text = "No items matched your query."
else
ErrorMsg.Text = ""
End If
End Sub
If an InStock field in my database has a bit value of '1' I need to make an 'Add to Cart' image button display, whereas if the value is '0', I need to show an 'Out of Stock' image button. I'm not sure where to do this - maybe in my BindDataList sub? Anway, I'm sure this is not difficult, but any suggestions would be very much appreciated.
Thanks
I'm having difficulty displaying a particular image button in a DataList depending on the value of a field in my SQL database. I'm using the following to execute a stored procedure and retrieve a dataset:
Sub getResultsbySubject(Source as Object, e as EventArgs)
myDataAdapter = New SqlDataAdapter("Pubs_SearchbySubject", myConnection)
myDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure
myDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@Search", SqlDbType.NVarChar, 255))
myDataAdapter.SelectCommand.Parameters("@Search").Value = frmSubjects.selectedvalue
resultDS = New DataSet()
myDataAdapter.Fill(resultDS, "Results")
dlResults.DataSource = resultDS.Tables("Results").DefaultView
Session("resultDSDataTable") = resultDS.Tables("Results")
BindDataList
myDataAdapter.Dispose()
myConnection.Close
End Sub
Sub BindDataList
dlResults.DataBind()
' Display a message if no results are found
If dlResults.Items.Count = 0 Then
ErrorMsg.Text = "No items matched your query."
else
ErrorMsg.Text = ""
End If
End Sub
If an InStock field in my database has a bit value of '1' I need to make an 'Add to Cart' image button display, whereas if the value is '0', I need to show an 'Out of Stock' image button. I'm not sure where to do this - maybe in my BindDataList sub? Anway, I'm sure this is not difficult, but any suggestions would be very much appreciated.
Thanks