ASP.NET程式中常用的三十三種代碼[5]

來源:互聯網
上載者:User
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();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.