gpt4 book ai didi

html - GridView 未显示在 asp.net 网页中

转载 作者:太空宇宙 更新时间:2023-11-04 14:04:56 30 4
gpt4 key购买 nike

我正在 build 我的网站,一切都很好,但是当我运行我的网站时, GridView 没有出现,请任何人帮助我如何解决这个问题并让 GridView 出现在页面上

这是 aspx 代码:

<%@ Page Title="" Language="VB" MasterPageFile="~/Member.master" AutoEventWireup="false" CodeFile="Order.aspx.vb" Inherits="Order" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">


<script type="text/javascript">
var oldgridcolor;
function SetMouseOver(element) {
oldgridcolor = element.style.backgroundColor;
element.style.backgroundColor = '#ffeb95';
element.style.cursor = 'pointer';
element.style.textDecoration = 'underline';
}
function SetMouseOut(element) {
element.style.backgroundColor = oldgridcolor;
element.style.textDecoration = 'none';
}
</script>


</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


<div style="margin-right: 0cm; margin-left: 4.1cm; height: 679px; background-color: #CC0000; width: 1038px; margin-bottom: 0px; margin-top: 109px;">

<fieldset style="width:230px;">
<legend style="font-family: 'Times New Roman', Times, serif; font-size: xx-large; color: #FFFF00; font-weight: normal; font-style: normal">Menu<asp:SqlDataSource
ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:conStr %>"
SelectCommand="SELECT * FROM [Menu]">
</asp:SqlDataSource>
<br />
</legend>
<asp:GridView ID="MenuGrid" runat="server" AutoGenerateColumns="false"
BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataKeyNames="MealNo" DataSourceID="SqlDataSource1"
Width="990px" GridLines="None" OnRowDataBound="EmpGridView_RowDataBound">
<Columns>
<asp:BoundField DataField="MealNo" HeaderText="MealNo" />
<asp:BoundField DataField="MealName" HeaderText="MealName" />
<asp:BoundField DataField="Desp" HeaderText="Desp" />
<asp:BoundField DataField="Price" HeaderText="Price" />
<asp:BoundField DataField="MealCateID" HeaderText="MealCateID"/>
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</fieldset>
</div>
</asp:Content>

vb代码:

    Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration

Partial Class Order
Inherits System.Web.UI.Page


Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
BindEmpGrid()
End If
End Sub
Private Sub BindEmpGrid()
Dim dt As New DataTable()
Try
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("conStr").ConnectionString)
Dim adp As New SqlDataAdapter("Select * from Menu", con)
adp.Fill(dt)

If dt.Rows.Count > 0 Then
MenuGrid.DataSource = dt
MenuGrid.DataBind()
Else
MenuGrid.DataSource = Nothing
MenuGrid.DataBind()
End If
Catch ex As Exception
Response.Write("Error Occured: " & ex.ToString())
Finally
dt.Clear()
dt.Dispose()
End Try
End Sub

Protected Sub EmpGridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles MenuGrid.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Attributes("onmouseover") = "javascript:SetMouseOver(this)"
e.Row.Attributes("onmouseout") = "javascript:SetMouseOut(this)"
End If
End Sub

End Class

最佳答案

您没有在任何地方打开连接。打开它或更好地包装在 Using ... End Using 中,像这样尝试:

Using con As New sqlConnection(ConfigurationManager.ConnectionStrings("conStr").ConnectionString)
Dim adp As New SqlDataAdapter("Select * from Menu", con)
adp.Fill(dt)
End Using

关于html - GridView 未显示在 asp.net 网页中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21202658/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com