ASP.NET中使用了一个Repeater,然后使用了DataRowView来获取当前行的值,为什么调试过程中DataRowView为空 protected void RepeaterDepart_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            DataRowView rowView = (DataRowView)e.Item.DataItem;
            var row = (HAMS1.DAL.HsDataSet.T_OrderListRow)rowView.Row;
            if (row.ExpertsName == "关羽")
            {
                h1.Text = row.ExpertsName;
            }
            
        }
为什么DataRowView总是取不到值?

解决方案 »

  1.   

     if(e.Row.RowIndex>-1)//避免DataRowView=null的出现
            {
                DataRowView rowView = e.Row.DataItem as DataRowView;        }
     else
            { 
              //原因
            }
      

  2.   


    e中没有row这个属性啊??
      

  3.   

    看错了。。你可以在判断为null的地方加个if判断你使用嵌套了吗?
      

  4.   

    没有使用嵌套··就是直接取repeater的行,难道还要先取出数据集再操作么?
      

  5.   

    .........
    protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            for (int i = 0; i < this.Repeater1.Items.Count; i++)
            {
                if ((this.Repeater1.Items[i].FindControl("控件ID") as TextBox).Text == "关羽")
                {
                    h1.Text = "关羽";
                }
            }
        }