【发布时间】:2011-06-09 19:27:58
【问题描述】:
如果产品在数据库的“Offered”列中有数字“1”,我需要在 gridview 中的产品旁边显示“on Offer”指示器。如果为零,则不显示。有什么方法可以实现吗?谢谢。
在我的产品列表页面中: 将 objCat 调暗为新类别 将 objProduct 调暗为新产品 将 i 调暗为整数 Dim boolError As Boolean = False
objCat.ID = CType(Request.QueryString("CatID"), 整数)
' 获取类别的详细信息
objCat.GetDetails()
' 显示类别名称
lblCatName.Text = objCat.Name
lblCatName2.Text = objCat.Name
' 显示分类描述
lblCatDesc.Text = objCat.Description
objCat.GetOfferedProducts()
For i = 0 To gvProduct.Rows.Count - 1
' Get the ProductId from the first cell
objProduct.ID = gvProduct.Rows(i).Cells(0).Text
Dim lblOffer As Label
lblOffer = CType(gvProduct.Rows(i).FindControl("lblOffer"), Label)
If objCat.Offered = "1" Then
lblOffer.Visible = True
Else
lblOffer.Visible = False
End If
下一个
gvProduct.DataSource = objCat.GetProducts()
gvProduct.DataBind()
在我的类别中: 公共子 GetOfferedProducts()
' Define a conection to database
' Read connection string from the web.config file.
Dim strConn As String
strConn = ConfigurationManager.ConnectionStrings("AppDb").ToString
Dim conn As New SqlConnection(strConn)
' Retrieve details of a given Category ID from the database
Dim strSql As String
strSql = "SELECT * FROM CatProduct cp INNER JOIN Product p " & _
"ON cp.ProductID=p.ProductID INNER JOIN Category c ON cp.CategoryID=c.CategoryID " & _
"WHERE cp.CategoryID=@CategoryID"
'定义一个Command对象来执行SQL语句
将 cmd 调暗为新的 SqlCommand(strSql, conn)
' 为 SQL 命令添加参数
cmd.Parameters.AddWithValue("@CategoryID", ID)
' 定义一个数据适配器来获取数据
Dim da As New SqlDataAdapter(cmd)
' 定义一个数据集来保存获取的数据
暗淡 ds 作为新数据集
' 打开数据库连接
conn.Open()
da.Fill(ds, "CatProduct")
'关闭数据库连接
conn.Close()
如果 ds.Tables("CatProduct").Rows.Count 0 那么
Name = ds.Tables("CatProduct").Rows(0)("CatName")
说明 = ds.Tables("CatProduct").Rows(0)("CatDesc")
ImageFile = ds.Tables("CatProduct").Rows(0)("CatImage")
提供 = CType(ds.Tables("CatProduct").Rows(0)("Offered"), 整数)
结束如果
【问题讨论】:
标签: asp.net