ASP.NET 設(shè)計(jì)中的 N 個(gè)技巧_.Net教程

      編輯Tag賺U幣
      教程Tag:暫無(wú)Tag,歡迎添加,賺取U幣!

      推薦:asp.net讀取數(shù)據(jù)庫(kù)亂碼的解決完全方案
      在下面的映射表中加入gb2312 和gbk,就不會(huì)有亂碼了,源碼在下面提供一位網(wǎng)友寫(xiě)的程序改了改 private static void LoadCharsetMap() {

      asp.net中DataGrid雙行跨列表頭設(shè)計(jì)心得!
      一、DataGrid的屬性設(shè)置
        1. AllowPaging: true
        2. PageStyle->Position: TopAndBottom
      3. 可選:PageStyle->HorizonAlign: Center(使文本居中顯示)
        4. 可選:ItemStyle->HorizonAlign: Center(使文本居中顯示)
      二、代碼部分
        1.首先,使DataGrid綁定數(shù)據(jù)庫(kù)中某個(gè)表,例如:
      private void Page_Load(object sender, System.EventArgs e)
      {
      // 在此處放置用戶代碼以初始化頁(yè)面
      if(!IsPostBack)
      {
      SqlConnection myConn=new SqlConnection("server=localhost;uid=sa;pwd=sa;database=db_test");
      SqlDataAdapter da=new SqlDataAdapter("Select * from 個(gè)人",myConn);
      DataSet ds=new DataSet();
      da.Fill(ds,"gr");
      dgGeRen.DataSource=ds.Tables["gr"].DefaultView;
      dgGeRen.DataBind();


      }
        2.為DataGrid添加ItemCreated事件的處理函數(shù)、
        3.為了判斷DataGrid中的兩個(gè)(上下)Pager的位置,我們可以使用一個(gè)全局變量來(lái)判斷。
      定義一個(gè)全局變量 private int m_CreatePageTimes = 0;
        4.為DataGrid的ItemCreated事件的處理函數(shù)添加內(nèi)容,如下:
      private void dgGeRen_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
      {
      switch(e.Item.ItemType)
      {
      //case(ListItemType.Pager):
      case ListItemType.Pager:
      {
      if(m_CreatePageTimes == 0)
      {
      DataGridItem row=(DataGridItem)e.Item;
      row.Cells.Clear();

      //row.BackColor=Color.Navy; //背景色
      //row.ForeColor=Color.Red; //前景色

      row.HorizontalAlign=HorizontalAlign.Center;//使文本居中顯示

      TableCell cell0=new TableCell();
      cell0.RowSpan=2;
      cell0.Controls.Add(new LiteralControl("姓名"));

      TableCell cell1=new TableCell();
      cell1.ColumnSpan=2;  //默認(rèn)的ColumnSpan值為1
      cell1.Text="住房地址信息";

      //也可如此:cell1.Controls.Add(new LiteralControl("住房地址信息"));

      //TableCell cell2=new TableCell();
      //cell2.Controls.Add(new LiteralControl(""));
      TableCell cell2=new TableCell();
      cell2.RowSpan=2;
      cell2.Text="出生日期";

      row.Cells.Add(cell0);
      row.Cells.Add(cell1);
      row.Cells.Add(cell2);


      m_CreatePageTimes ;
      }
      break;
      }
      case ListItemType.Header:
      {
      DataGridItem head=(DataGridItem)e.Item;
      head.Cells.Clear();

      //head.VerticalAlign=VerticalAlign.Middle;
      //head.HorizontalAlign=HorizontalAlign.Center;

      //TableCell cell00=new TableCell();
      //cell00.RowSpan=2;
      //cell00.Text="姓名";

      TableCell cell01=new TableCell();
      cell01.Text="樓號(hào)";

      TableCell cell02=new TableCell();
      cell02.Text="房號(hào)";

      //TableCell cell03=new TableCell();
      //cell03.Text="出生日期";

      //head.Cells.Add(cell00);
      head.Cells.Add(cell01);
      head.Cells.Add(cell02);
      //head.Cells.Add(cell03);
      break;
      }

      }

      }

      分享:ASP.NET1.1中動(dòng)態(tài)樹(shù)的實(shí)現(xiàn)
      因?yàn)锳SP.NET1.1沒(méi)有像ASP.NET2.0那樣默認(rèn)提供TreeView控件,所以ASP.NET1.1中實(shí)現(xiàn)動(dòng)態(tài)樹(shù)就不像ASP.NET2.0中那樣簡(jiǎn)單了,但是也并沒(méi)有復(fù)雜多少,只是多了點(diǎn)步驟而已。下面就讓我們分三步來(lái)在ASP.N

      共2頁(yè)上一頁(yè)12下一頁(yè)
      來(lái)源:模板無(wú)憂//所屬分類:.Net教程/更新時(shí)間:2008-08-22
      相關(guān).Net教程