本帖最后由 peace12211214 于 2012-08-18 11:36:16 编辑

解决方案 »

  1.   

    后台.cs的代码:
     protected void Page_Load(object sender, EventArgs e)
            {
                string exam_id = Request.QueryString ["id"];
                SqlConnection conn = ConnectAccess.OC();
                conn.Open();
                //找到试卷中的题目在item表中的id。
                string str = "select item_id from exam_item where exam_id = " + exam_id + "";
                SqlCommand cmd = new SqlCommand(str, conn);
                SqlDataAdapter sda = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                sda.Fill(ds, "item_list");
                conn.Close();            int item_count = ds.Tables["item_list"].Rows.Count;
                conn = ConnectAccess.OC();
                conn.Open();
                DataColumn dc = new DataColumn ();
                dc = ds.Tables["item_list"].Columns.Add("item_title", typeof(string));
                dc = ds.Tables["item_list"].Columns.Add("order_id", typeof(int));
                for (int i = 0; i < item_count; i++)
                {
                    str = "select * from item where id = " + ds.Tables["item_list"].Rows[i]["item_id"] + "";
                    cmd = new SqlCommand(str, conn);
                    sda = new SqlDataAdapter(cmd);
                    sda.Fill(ds, "item_info");
                    ds.Tables["item_list"].Rows[i]["item_title"] = ds.Tables["item_info"].Rows[0]["item_title"];
                    ds.Tables["item_list"].Rows[i]["order_id"] = i + 1;
                }
                item_list_view_exam.DataSource = ds.Tables["item_list"];
                item_list_view_exam.DataBind();
                conn.Close();        }
           
            //绑定题目信息时,绑定题目的选项
             protected void item_list_view_exam_ItemDataBound(object sender, RepeaterItemEventArgs e)  
             {
                 SqlConnection conn = ConnectAccess.OC();
                 conn.Open();
                 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)       
                 {           
                     Repeater rep = e.Item.FindControl("result_list_view_exam") as Repeater;           
                     DataRowView rowv = (DataRowView)e.Item.DataItem;
                 //以下是读取Repeater1中绑定数据的字段,用于Repeater2的查询条件          
                 string strDecide_No =rowv["item_id"].ToString();                    
                 //以下是Repeater2的数据读取和绑定  ,调用数据操作类执行SQL语句       
                 string str = " select * from result where item_id = "+Convert.ToInt32(strDecide_No)+"";             SqlCommand cmd = new SqlCommand(str, conn);
                 SqlDataAdapter sda = new SqlDataAdapter(cmd);
                 DataSet ds = new DataSet ();
                 sda.Fill(ds, "result_list");             rep.DataSource = ds.Tables["result_list"];  
                 rep.DataBind();     
                 }   
             }
      

  2.   

    另外,页面中要加
    <%@ Page Language="C#"  AutoEventWireup="true" %>
      

  3.   

    的确是因为我的数据源为空导致的。原来如果repeater控件的数据源为空,其itemdatabound是无法触发的。不知道repeater控件的其他事件是否也是如此,还是说只影响与数据源有关的事件。
      

  4.   

    是的,没有数据,itemdatabound是不执行的。数据源为空你要是实现什么?