谁在的话帮下忙!
我的GridView点击编辑的时候总是自动调用RowDataBound函数,然后就说里面 "未将对象引用设置到对象的实例。 "
RowDataBound中代码如下:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label lbl_one = (Label)e.Row.Cells[1].FindControl( "Label1 ");
Label lbl_two = (Label)e.Row.Cells[2].FindControl( "Label2 ");
//=====================
lbl_one.Text = lbl_one.Text.Replace( " ", " ");
lbl_one.Text = lbl_one.Text.Trim();
if (lbl_one.Text.Length > 20)
{
lbl_one.Text = lbl_one.Text.Substring(0, 10) + "... ";
}
//======================
lbl_two.Text = lbl_two.Text.Replace( " ", " ");
lbl_two.Text = lbl_two.Text.Trim();
if (lbl_two.Text.Length > 10)
{
lbl_two.Text = lbl_two.Text.Substring(0, 10) + "... ";
}
}
}
[解决办法]
老兄,Cells是单元格来的,直接使用Cells[1].Text不行吗?
[解决办法]
你不在单元格里找,直接找行试试