1. 界面添加

 

类型

 

对象名

 

="color:black;font-family:宋体;mso-ascii-font-family:'timesnewroman';mso-hansi-font-family:'timesnewroman';mso-bidi-font-family:arial">
=msonormalstyle="margin:0cm0cm0pt;text-align:center"align=center>
Text属性值

 

="color:black;font-family:宋体;mso-ascii-font-family:'timesnewroman';mso-hansi-font-family:'timesnewroman';mso-bidi-font-family:arial">
=msonormalstyle="margin:0cm0cm0pt;text-align:center"align=center>
Button

 

=msonormalstyle="margin:0cm0cm0pt;text-align:center"align=center>
Button1

 

=en-usstyle="font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-bidi-font-size:9.0pt;mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:center"align=center>
显示

 

="font-family:宋体;mso-ascii-font-family:'timesnewroman';mso-hansi-font-family:'timesnewroman'">
=msonormalstyle="margin:0cm0cm0pt;text-align:center"align=center>
DataGrid

 

=en-us>
=msonormalstyle="margin:0cm0cm0pt;text-align:center"align=center>
DataGrid1

 

=en-us>
=msonormalstyle="margin:0cm0cm0pt;text-align:center"align=center>
 

 

=msonormalstyle="margin:0cm0cm0pt;text-align:center"align=center>
 

 

2. 代码的实现

 

双击“显示”按钮

 

privatevoidButton1_Click(objectsender,System.EventArgse)

 

{

 

    NhDataBind();

 

}

 

privatevoidNhDataBind()//数据绑定代码

 

{

 

     mCfg=newConfiguration();

 

     mCfg.AddXmlFile(System.Web.HttpContext.Current.Server.MapPath("Userhbm.xml"));

 

     ISessionvSession=mCfg.BuildSessionFactory().OpenSession();

 

     ITransactionvTransaction=vSession.BeginTransaction();

 

     try

 

    {

 

         IListvList=vSession.Find("fromWebNhibernate.EntityClass");//HQL语句实现数据查询

 

         DataGrid1.DataSource=vList;

 

         DataGrid1.DataBind();

 

         vTransaction.Commit();

 

         Labmessage.Text="OK";

 

     }

 

     catch(Exceptionex)

 

     {

 

         vTransaction.Rollback();

 

         Labmessage.Text="Error";

 

     }

 

     finally

 

     {

 

          vSession.Close();

 

     }

 

}

 

 

 

创建DataGird事件处理

 

privatevoidDataGrid1_PageIndexChanged(objectsource,System.Web.UI.WebControls.DataGridPageChangedEventArgse)

 

{

 

    DataGrid1.CurrentPageIndex=e.NewPageIndex;

 

    NhDataBind();

 

}
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt">
="mso-tab-count:1">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="color:blue">
="color:blue">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=en-usstyle="font-size:9pt;color:blue;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="font-family:宋体;mso-ascii-font-family:'timesnewroman';mso-hansi-font-family:'timesnewroman'">
=en-us>
="font-family:宋体;mso-ascii-font-family:'timesnewroman';mso-hansi-font-family:'timesnewroman'">
=msonormalstyle="margin:0cm0cm0pt">
=msonormalstyle="margin:0cm0cm0pt">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="color:blue">
="mso-tab-count:1">
="mso-tab-count:2">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="color:blue">
="mso-tab-count:1">
="mso-tab-count:2">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:1">
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:3">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="color:blue">
="mso-tab-count:2">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:2">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:2">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="mso-tab-count:2">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="color:blue">
="mso-tab-count:2">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="color:blue">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=en-usstyle="font-size:9pt;color:blue;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="color:blue">
="color:blue">
=en-usstyle="font-size:9pt;font-family:新宋体;mso-hansi-font-family:'timesnewroman';mso-font-kerning:0pt">
=msonormalstyle="margin:0cm0cm0pt;text-align:left;mso-layout-grid-align:none"align=left>
="font-family:宋体;mso-ascii-font-family:'timesnewroman';mso-hansi-font-family:'timesnewroman'">
=msonormalstyle="margin:0cm0cm0pt">
="font-family:宋体;mso-ascii-font-family:'timesnewroman';mso-hansi-font-family:'timesnewroman'">
=en-us>
=msonormalstyle="margin:0cm0cm0pt18pt;text-indent:-18pt;tab-stops:list18.0pt;mso-list:l0level1lfo1">
=msonormalstyle="margin:0cm0cm0pt">

相关文章:

  • 2021-10-06
  • 2021-10-30
  • 2022-01-11
  • 2022-02-15
  • 2021-08-11
  • 2021-11-25
  • 2022-12-23
  • 2022-01-23
猜你喜欢
  • 2022-03-09
  • 2021-11-29
  • 2021-06-07
  • 2021-08-05
  • 2021-08-25
  • 2022-12-23
相关资源
相似解决方案