2011年5月27日 星期五

測試內容

ear All,

來自EMAIL的問候

With my best wishes,
Jack(6906)

2011年5月26日 星期四

GridView include anthor GridView

首先必須撰寫再RowCreated並且SelectIndexChanged務必使用GridView1.DataBind();

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        //記錄當選取實記錄下當時的索引值
        int user_select = Convert.ToInt32(GridView1.SelectedIndex.ToString());
        // e.Row.RowType == DataControlRowType.Pager代表原本的GridView1已經建置到最後分頁功能的部分,已經建置完畢
        if (user_select >= 0 & e.Row.RowType == DataControlRowType.Pager)
        {
            //前面mycell_0以及mycell_1仍須建置但是不放值,GrideView2放在 mycell_2
            GridViewRow myRow = new GridViewRow(user_select + 1, -1, DataControlRowType.DataRow, DataControlRowState.Selected);
            TableCell mycell_0 = new TableCell();
            mycell_0.BackColor = System.Drawing.Color.RoyalBlue;
            TableCell mycell_1 = new TableCell();
            mycell_1.BackColor = System.Drawing.Color.RoyalBlue;
            TableCell mycell_2 = new TableCell();
            mycell_2.BackColor = System.Drawing.Color.RoyalBlue;
            myRow.Cells.Add(mycell_0);
            myRow.Cells.Add(mycell_1);
            if (Page.IsPostBack)
            {
                UserControl my_uc = new UserControl();
                //利用WebControl來建置另一個GridView2
                my_uc = (UserControl)LoadControl("Learn_WebUserControl.ascx");
                mycell_2.Controls.Add(my_uc);
                myRow.Cells.Add(mycell_2);
            }
            myRow.Visible = true;
            //要加二我理解為原本GrideView1的原本那一列再加上GrideView2的Header,因此必須在Index值上加上user_select + 2
            GridView1.Controls[0].Controls.AddAt((user_select + 2), myRow);

        }

Session啟用

session必須在下方aspx檔中先行開啟

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Learn_ControlMaster.aspx.cs" Inherits="CW_WEB_Learn_ControlMaster" EnableSessionState="True" %>

否則會出現以下錯誤訊息,如果發現再有問題請重新建置網頁即可。