问题描述
您好,
i我正在尝试在gridview的RowDataBound事件中设置位于gridview中的标签文本。该代码的代码如下:
Hello,
i am trying to set label text which resides in gridview on RowDataBound event of gridview.The code for the same is as follows:
protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int day=Convert.ToInt32(DropDownList3.SelectedValue);
int days = System.DateTime.DaysInMonth(2013,day);
Label lab = (Label)e.Row.FindControl("d");
lab.Text=days.ToString();
}
}
在上面的代码中,''''是gridview中标签的id。在突出显示的行中,我收到错误对象参考没有设置为对象的实例。据我所知,新的标签没有被创建。然后如何将在此事件中计算的值分配给gridviews标签?任何帮助都非常适合...
问候
In the above code,''d'' is the id of the label in the gridview.On the highlighted line i am getting error that OBJECT REFERENCE NOT SET TO INSTANCE OF AN OBJECT.As per as i understand,the new label is not being created.then how to assign values calculated in this event to gridviews label?Any help is greatly appriciated...
Regards
推荐答案
DataControlRowType rtype = e.Row.RowType;
if (rtype == DataControlRowType.DataRow && rtype != DataControlRowType.Footer && rtype != DataControlRowType.Header)
{
//
}
在DEBUG模式下方法中简单使用断点将清除所有疑点和可能的修复。
A simple use of breakpoint in the method in DEBUG mode will clear all the doubts and possible fix.
这篇关于对象引用未设置为对象的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!