怎样定时局部刷新datagrid?
用vs2008中自带的AJAXExtensions,代码如下:<htmlxmlns="http://www.w3.org/1999/xhtml"><headid="Hea...
用vs2008中自带的AJAX Extensions,代码如下:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>数据的分布</title>
</head>
<body style="margin-top:0; background-color: Black">
<form id="form1" runat="server">
<div>
<table width="1024" border="0" align="center">
<tr>
<td style="text-align:center"><asp:Label ID="lblMsg" ForeColor="Yellow" Font-Names="黑体" Font-Size="35pt" Text="数据明细" runat="server" Width="382px"></asp:Label></td>
</tr>
</table>
<table width="99%" border="1">
<tr>
<td width="100%" height="393" valign="top">
<table width="100%" border="0">
<tr>
<td valign="top" align="Left">
<asp:DataGrid
id="dtGrid"
AllowPaging="false"
PageSize="12"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Center"
HeaderStyle-BackColor="#000000"
HeaderStyle-ForeColor="#ff0000"
HeaderStyle-Font-Size="28pt"
itemstyle-backcolor="#000000"
itemstyle-forecolor="#00ff00"
BorderColor="Black"
CellPadding="2"
CellSpacing="0"
Font-Size="28pt"
Font-Name="黑体,Arial"
DataKeyField="ProductNM"
AutoGenerateColumns="false"
Width="100%"
runat="server" >
<Columns>
<asp:BoundColumn DataField="UserCodeNM" HeaderText="用户名称" />
<asp:BoundColumn DataField="ProductNM" HeaderText="产品名称" />
<asp:BoundColumn DataField="Qty" HeaderText="产品数量" />
<asp:BoundColumn DataField="LotCount" HeaderText="产品个数" />
<asp:BoundColumn DataField="FactoryStartDate" HeaderText="产品日期" DataFormatString="{0:yyyy-MM-dd}" />
</Columns>
</asp:DataGrid>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=192.168.0.110;database=InfoDB;uid=sa;pwd=;");
//初始化
SqlDataAdapter sda = new SqlDataAdapter("select * from Grade", conn);
DataSet ds = new DataSet();
sda.Fill(ds, "Grade");
datagrid.DataSource = ds.Tables["Grade"].DefaultView;
datagrid.DataBind();
} 展开
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>数据的分布</title>
</head>
<body style="margin-top:0; background-color: Black">
<form id="form1" runat="server">
<div>
<table width="1024" border="0" align="center">
<tr>
<td style="text-align:center"><asp:Label ID="lblMsg" ForeColor="Yellow" Font-Names="黑体" Font-Size="35pt" Text="数据明细" runat="server" Width="382px"></asp:Label></td>
</tr>
</table>
<table width="99%" border="1">
<tr>
<td width="100%" height="393" valign="top">
<table width="100%" border="0">
<tr>
<td valign="top" align="Left">
<asp:DataGrid
id="dtGrid"
AllowPaging="false"
PageSize="12"
PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Center"
HeaderStyle-BackColor="#000000"
HeaderStyle-ForeColor="#ff0000"
HeaderStyle-Font-Size="28pt"
itemstyle-backcolor="#000000"
itemstyle-forecolor="#00ff00"
BorderColor="Black"
CellPadding="2"
CellSpacing="0"
Font-Size="28pt"
Font-Name="黑体,Arial"
DataKeyField="ProductNM"
AutoGenerateColumns="false"
Width="100%"
runat="server" >
<Columns>
<asp:BoundColumn DataField="UserCodeNM" HeaderText="用户名称" />
<asp:BoundColumn DataField="ProductNM" HeaderText="产品名称" />
<asp:BoundColumn DataField="Qty" HeaderText="产品数量" />
<asp:BoundColumn DataField="LotCount" HeaderText="产品个数" />
<asp:BoundColumn DataField="FactoryStartDate" HeaderText="产品日期" DataFormatString="{0:yyyy-MM-dd}" />
</Columns>
</asp:DataGrid>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source=192.168.0.110;database=InfoDB;uid=sa;pwd=;");
//初始化
SqlDataAdapter sda = new SqlDataAdapter("select * from Grade", conn);
DataSet ds = new DataSet();
sda.Fill(ds, "Grade");
datagrid.DataSource = ds.Tables["Grade"].DefaultView;
datagrid.DataBind();
} 展开
展开全部
aspx文件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>数据的分布</title>
<script type="text/javascript" language="javascript">
var sh = setInterval('refresh()', 1000);
function refresh() {
document.getElementById('<%= HiddenButton.ClientID %>').click();
}
</script>
</head>
<body style="margin-top: 0; background-color: Black">
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptmanager1" runat="server">
</asp:ScriptManager>
<div>
<table width="1024" border="0" align="center">
<tr>
<td style="text-align: center">
<asp:Label ID="lblMsg" ForeColor="Yellow" Font-Names="黑体" Font-Size="35pt" Text="数据明细"
runat="server" Width="382px"></asp:Label>
</td>
</tr>
</table>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<table width="99%" border="1">
<tr>
<td width="100%" height="393" valign="top">
<table width="100%" border="0">
<tr>
<td valign="top" align="Left">
<asp:DataGrid ID="dtGrid" AllowPaging="false" PageSize="12" PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Center" HeaderStyle-BackColor="#000000" HeaderStyle-ForeColor="#ff0000"
HeaderStyle-Font-Size="28pt" ItemStyle-BackColor="#000000" ItemStyle-ForeColor="#00ff00"
BorderColor="Black" CellPadding="2" CellSpacing="0" Font-Size="28pt" Font-Name="黑体,Arial"
DataKeyField="ProductNM" AutoGenerateColumns="false" Width="100%" runat="server">
<Columns>
<asp:BoundColumn DataField="UserCodeNM" HeaderText="用户名称" />
<asp:BoundColumn DataField="ProductNM" HeaderText="产品名称" />
<asp:BoundColumn DataField="Qty" HeaderText="产品数量" />
<asp:BoundColumn DataField="LotCount" HeaderText="产品个数" />
<asp:BoundColumn DataField="FactoryStartDate" HeaderText="产品日期" DataFormatString="{0:yyyy-MM-dd hh:mm:ss}" />
</Columns>
</asp:DataGrid>
<asp:Button ID="HiddenButton" runat="server" style="display:none" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>数据的分布</title>
<script type="text/javascript" language="javascript">
var sh = setInterval('refresh()', 1000);
function refresh() {
document.getElementById('<%= HiddenButton.ClientID %>').click();
}
</script>
</head>
<body style="margin-top: 0; background-color: Black">
<form id="form1" runat="server">
<asp:ScriptManager ID="scriptmanager1" runat="server">
</asp:ScriptManager>
<div>
<table width="1024" border="0" align="center">
<tr>
<td style="text-align: center">
<asp:Label ID="lblMsg" ForeColor="Yellow" Font-Names="黑体" Font-Size="35pt" Text="数据明细"
runat="server" Width="382px"></asp:Label>
</td>
</tr>
</table>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="true">
<ContentTemplate>
<table width="99%" border="1">
<tr>
<td width="100%" height="393" valign="top">
<table width="100%" border="0">
<tr>
<td valign="top" align="Left">
<asp:DataGrid ID="dtGrid" AllowPaging="false" PageSize="12" PagerStyle-Mode="NumericPages"
PagerStyle-HorizontalAlign="Center" HeaderStyle-BackColor="#000000" HeaderStyle-ForeColor="#ff0000"
HeaderStyle-Font-Size="28pt" ItemStyle-BackColor="#000000" ItemStyle-ForeColor="#00ff00"
BorderColor="Black" CellPadding="2" CellSpacing="0" Font-Size="28pt" Font-Name="黑体,Arial"
DataKeyField="ProductNM" AutoGenerateColumns="false" Width="100%" runat="server">
<Columns>
<asp:BoundColumn DataField="UserCodeNM" HeaderText="用户名称" />
<asp:BoundColumn DataField="ProductNM" HeaderText="产品名称" />
<asp:BoundColumn DataField="Qty" HeaderText="产品数量" />
<asp:BoundColumn DataField="LotCount" HeaderText="产品个数" />
<asp:BoundColumn DataField="FactoryStartDate" HeaderText="产品日期" DataFormatString="{0:yyyy-MM-dd hh:mm:ss}" />
</Columns>
</asp:DataGrid>
<asp:Button ID="HiddenButton" runat="server" style="display:none" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
额,你绑定下啊,然后设置下刷新时间就好啦
还是你是问怎么绑啊?
还是你是问怎么绑啊?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询