ASP.NET程序中常用的三十三种代码(5)

  24.DataGrid选定比较底下的行时,为什么总是刷新一下,然后就滚动到了最上面,刚才选定的行因屏幕的关系就看不到了。
  
  page_load
  page.smartNavigation=true
  
    25.在Datagrid中修改数据,当点击编辑键时,数据出现在文本框中,怎么控制文本框的大小 ?
  
  private void DataGrid1_ItemDataBound(obj sender,DataGridItemEventArgs e)
  {
   for(int i=0;i<e.Item.Cells.Count-1;i++)
    if(e.Item.ItemType==ListItemType.EditType)
    {
     e.Item.Cells[i].Attributes.Add("Width", "80px")
    }
  }
  
    26.对话框
  
  private static string ScriptBegin = "<script language=\"JavaScript\">";
  private static string ScriptEnd = "</script>";
  
  public static void ConfirmMessageBox(string PageTarget,string Content)
  {
   string ConfirmContent="var retValue=window.confirm(’"+Content+"’);"+"if(retValue){window.location=’"+PageTarget+"’;}";
  
   ConfirmContent=ScriptBegin + ConfirmContent + ScriptEnd;
  
   Page ParametERPage = (Page)System.Web.HttpContext.Current.Handler;
   ParameterPage.ReGISterStartupScript("confirm",ConfirmContent);
   //Response.Write(strScript);
  }
  
    27. 将时间格式化:string aa=DateTime.Now.ToString("yyyy年MM月dd日");
  
    1.1 取当前年月日时分秒
  
  currentTime=System.DateTime.Now;
  
    1.2 取当前年
  
  int 年= DateTime.Now.Year;
  
    1.3 取当前月
  
  int 月= DateTime.Now.Month;
  
    1.4 取当前日
  
  int 日= DateTime.Now.Day;
  
    1.5 取当前时
  
  int 时= DateTime.Now.Hour;
  
    1.6 取当前分
  
  int 分= DateTime.Now.Minute;
  
    1.7 取当前秒
  
  int 秒= DateTime.Now.Second;
  
    1.8 取当前毫秒
  
  int 毫秒= DateTime.Now.Millisecond;
  
    28.自定义分页代码:
  
    先定义变量 :
  
  public static int pageCount; //总页面数
  public static int curPageIndex=1; //当前页面
  
    下一页:
  
  if(DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1))
  {
   DataGrid1.CurrentPageIndex += 1;
   curPageIndex+=1;
  }
  
  bind(); // DataGrid1数据绑定函数
  
    上一页:
  
  if(DataGrid1.CurrentPageIndex >0)
  {
   DataGrid1.CurrentPageIndex += 1;
   curPageIndex-=1;
  }
  
  bind(); // DataGrid1数据绑定函数
  
    直接页面跳转:
  
  int a=int.Parse(JumpPage.Value.Trim());//JumpPage.Value.Trim()为跳转值
  
  if(a<DataGrid1.PageCount)
  {
   this.DataGrid1.CurrentPageIndex=a;
  }
  
  bind(); 
  
原文地址:https://www.cnblogs.com/wuhuihui_dotnet/p/279341.html