一个DataGrid多次绑定不同数据的时候我的用法

datagrid|数据

在一个页面中要实现数据全部的显示和搜索.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;

namespace NetBarView.AdminManage
{
 /// <summary>
 /// showlog 的摘要说明。
 /// </summary>
 public class showlog : System.Web.UI.Page
 {
  private string conStr = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
  protected System.Web.UI.WebControls.TextBox tbSearch;
  protected System.Web.UI.WebControls.Button btnSearch;
  protected System.Web.UI.WebControls.DataGrid dg;
 
  private void Page_Load(object sender, System.EventArgs e)
  {
   // 在此处放置用户代码以初始化页面
   if(!this.IsPostBack)
   {
    BindToDG();
   }
  }
  private void BindToDG()
  {
   dg.DataSource = SqlHelper.ExecuteDataset(conStr,CommandType.StoredProcedure,"mediaLogList");
   dg.DataKeyField = "id";
   dg.DataBind();
  }

  #region Web 窗体设计器生成的代码
  override protected void OnInit(EventArgs e)
  {
   //
   // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
   //
   InitializeComponent();
   base.OnInit(e);
  }
  
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </summary>
  private void InitializeComponent()
  {   
   this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
   this.dg.PageIndexChanged += new System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.dg_PageIndexChanged);
   this.Load += new System.EventHandler(this.Page_Load);

  }
  #endregion

  private void dg_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
  {
   dg.CurrentPageIndex = e.NewPageIndex;
   if(this.tbSearch.Text == "")
   {
    BindToDG();
   }
   else
   {
    SearchBind();
   }
  }
  private void SearchBind()
  {
//   string sql = "select id,(select barname from baruser where id=barid)as barname,medianame,addtime from medialog where barname=@barname order by id desc";
   SqlParameter pm = new SqlParameter("@barname",SqlDbType.VarChar,50);
   pm.Value = this.tbSearch.Text;
   dg.DataSource = SqlHelper.ExecuteDataset(conStr,CommandType.StoredProcedure,"mediaLogSearch",pm);
   dg.CurrentPageIndex = 0;
   dg.DataKeyField = "id";
   dg.DataBind();
  }

  private void btnSearch_Click(object sender, System.EventArgs e)
  {
//   SearchBind();
  }
 }
}

<%@ Page language="c#" Codebehind="showlog.aspx.cs" AutoEventWireup="false" Inherits="NetBarView.AdminManage.showlog" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
 <HEAD>
  <title>showlog</title>
  <meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
  <meta name="CODE_LANGUAGE" Content="C#">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
 </HEAD>
 <body MS_POSITIONING="GridLayout" bgcolor="#799ae1" style="margin-left:0px">
  <form id="Form1" method="post" runat="server">
   <TABLE id="Table1" style="FONT-SIZE: 9pt; WIDTH: 600px" borderColor="#ccccff" cellSpacing="1"
    cellPadding="0" width="907" border="1">
    <TR>
     <TD style="HEIGHT: 25px" align="center" bgColor="#6699ff" colSpan="3">网吧电影观看日志</TD>
    </TR>
    <TR>
     <TD style="HEIGHT: 25px" align="center" colSpan="3"><FONT face="宋体">网吧搜索     
       <asp:TextBox id="tbSearch" runat="server"></asp:TextBox>      
       <asp:Button id="btnSearch" runat="server" Text="搜索"></asp:Button></FONT></TD>
    </TR>
    <TR>
     <TD style="WIDTH: 575px" vAlign="top" align="left" width="575" colSpan="2">
      <asp:DataGrid id="dg" runat="server" Width="384px" AutoGenerateColumns="False" AllowPaging="True"
       PageSize="30" Font-Size="X-Small" BorderColor="#3366CC" BorderStyle="None" BorderWidth="1px"
       BackColor="White" CellPadding="4">
       <FooterStyle ForeColor="#003399" BackColor="#99CCCC"></FooterStyle>
       <SelectedItemStyle Font-Bold="True" ForeColor="#CCFF99" BackColor="#009999"></SelectedItemStyle>
       <ItemStyle ForeColor="#003399" BackColor="White"></ItemStyle>
       <HeaderStyle Font-Bold="True" ForeColor="#CCCCFF" BackColor="#003399"></HeaderStyle>
       <Columns>
        <asp:BoundColumn DataField="id" HeaderText="编号">
         <HeaderStyle Width="40px"></HeaderStyle>
        </asp:BoundColumn>
        <asp:BoundColumn DataField="barname" HeaderText="网吧名称">
         <HeaderStyle Width="120px"></HeaderStyle>
        </asp:BoundColumn>
        <asp:BoundColumn DataField="medianame" HeaderText="观看电影">
         <HeaderStyle Width="120px"></HeaderStyle>
        </asp:BoundColumn>
        <asp:BoundColumn DataField="addtime" HeaderText="观看时间" DataFormatString="{0:d}">
         <HeaderStyle Width="60px"></HeaderStyle>
        </asp:BoundColumn>
       </Columns>
       <PagerStyle HorizontalAlign="Left" ForeColor="#003399" BackColor="#99CCCC" Mode="NumericPages"></PagerStyle>
      </asp:DataGrid>
     </TD>
     <TD width="2"></TD>
    </TR>
    <TR>
     <TD style="WIDTH: 1px"></TD>
     <TD align="center" style="WIDTH: 291px">
     </TD>
     <TD width="2"><FONT face="宋体"></FONT></TD>
    </TR>
   </TABLE>
  </form>
 </body>
</HTML>

时间: 2024-07-28 19:05:15

一个DataGrid多次绑定不同数据的时候我的用法的相关文章

在griw中如何通过一个函数去改变绑定的数据值

问题描述 我现在在做一个用户信息的绑定,密码我是通过MD5加密算法得出的,所以保存在数据库中的密码是已通过加密的数据,现我要把这个密码读出来,要把它显示成解了密的数据,怎么样把经加密的数据转换呢:例如:密码是admin,加密后在数据库中保存的是19-A2-85-41-44-B6-3A-8F-76-17-A6-F2-25-01-9B-12现我要把它通过解密函数user.Encrypt(stringpassword)读出来在gridview绑定要怎样表示呢 解决方案 解决方案二:MD5算法不可解密,

绑定gridview-在绑定GridView数据的时候发现有一个字段的值无法绑定

问题描述 在绑定GridView数据的时候发现有一个字段的值无法绑定 问题如上 if (e.Row.RowType == DataControlRowType.DataRow && e.Row.DataItem != null) { Ali0rderModel orderModel = e.Row.DataItem as Ali0rderModel; if (null != orderModel) { Label lblVersionType = e.Row.FindControl(&qu

web-在angualr中怎么写一个services绑定到数据

问题描述 在angualr中怎么写一个services绑定到数据 我写了一个例子,但是报错 html 代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" href="libs/bootstrap/dist/css/bootstrap.min.css"> </head> &

利用ASP.NET DataGrid显示主次关系的数据

asp.net|datagrid|数据|显示 大家在实际工作中有没有遇到要在DataGrid中显示带有主次结构的数据呢?如果你对ADO.NET和SQL Server2000熟悉的话,我们下面就举一个利用VS.NET自带的示例数据库Northwind和VB.NET来说明如何实现这一目标.首先,我们先准备要显示的带有主次结构的数据. 下面就是要绑定到HierarchicalDataGrid.aspx的VB.NET代码文件HierarchicalDataGrid.aspx.vb的内容: Imports

Silverlight 通过索引器绑定动态数据

转自http://www.cnblogs.com/forgetu/archive/2011/06/18/silverlight-binding-dynamic-object-anonymous-class.html 绑定动态数据是做 Silverlight 程序时经常会遇到的问题.本文介绍 Silverlight 通过绑定索引器实现绑定动态数据,即在设计时不知道数据的结构,如在设计时不知道要绑定的类有哪些属性. 绑定索引器是 Silverlight 4 新增的特性,这一特性使用我们可以在设计时不

关于DataGrid的值绑定

问题描述 询问一下,举个例子数据库里有两个字段分别是news_titlenews_information我想问的是DataGrid有没有办法显示数据的时候将news_title显示在news_information页眉上 解决方案 解决方案二:交叉表................解决方案三:引用楼主sqzerostorm的帖子: 将news_title显示在news_information页眉上 具体是什么意思?将news_title作为标题行?解决方案四:protectedvoidGridV

【50分】GridView绑定后台数据有重复值

问题描述 用GridView<asp:HyperLinkID="HyperLink1"runat="server"NavigateUrl='<%#"Default2.aspx?id="+Eval("任务标题")%>'Text='<%#Eval("任务标题")%>'Font-Overline="false"></asp:HyperLink>

分页-我想做一个基于jquery的可操作表格数据展示与处理的控件

问题描述 我想做一个基于jquery的可操作表格数据展示与处理的控件 我是新手,我想做一个基于jquery的可操作表格数据展示与数据处理控件,表格需要提供的功能是排序,搜索,设置基本的增删改,分页的功能,求具体思路.谢谢 解决方案 别求,你看看开源代码,比如jqgrid,这个是jquery的grid组件,看它的代码研究一下 解决方案二: 想做就做呗,思路看来源代码 解决方案三: 基本思路就是前台传递参数条件到后台,再返回结果到前台显示 解决方案四: 去看jquery自带的flexigrid吧,相

c# wpf-WPF问题 C# 窗体隐藏时清空绑定的数据问题

问题描述 WPF问题 C# 窗体隐藏时清空绑定的数据问题 现有一个window画面,加载了usercontrol,usercontrol上绑定了一些数据. 实现要求:在其他画面点击按钮,会隐藏这个window,并清空usercontrol上绑定的数据. 但是目前有这样一个问题,就是隐藏了画面后再表示时,数据会闪烁一下才清空(一定概率,时隔很久表示依然有该现象).如果将隐藏动作去掉,可以正常清空. 隐藏表示方法用的是visibility属性,代码流程是先做的清空绑定,再通过Notify通知画面更新