Reapter的嵌套问题:未将对象引用设置到对象的实例
protected void Page_Load(object sender, EventArgs e)
{
DataTable d1 = new DataTable();
d1.Columns.Add( "type_id ");
d1.Columns.Add( "type_name ");
DataRow dr1 = d1.NewRow();
dr1[ "type_id "] = 1;
dr1[ "type_name "] = "Asp.NET相关 ";
d1.Rows.Add(dr1);
DataRow dr2 = d1.NewRow();
dr2[ "type_id "] = 2;
dr2[ "type_name "] = "JavaScript相关 ";
d1.Rows.Add(dr2);
DataRow dr3 = d1.NewRow();
dr3[ "type_id "] = 3;
dr3[ "type_name "] = "AJAX相关 ";
d1.Rows.Add(dr3);
this.rpt_type.DataSource = d1;
this.rpt_type.DataBind();
}
protected void rpt_type_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
DataTable d2 = new DataTable();
d2.Columns.Add( "content_id ");
d2.Columns.Add( "Content_name ");
for (int i = 0; i < 10; i++)
{
DataRow dr = d2.NewRow();
dr[ "content_id "] = i;
dr[ "content_name "] = "Asp.NET相关的标题 " + i.ToString();
d2.Rows.Add(dr);
}
DataTable d3 = new DataTable();
d3.Columns.Add( "content_id ");
d3.Columns.Add( "Content_name ");
for (int i = 0; i < 10; i++)
{
DataRow dr = d3.NewRow();
dr[ "content_id "] = i;
dr[ "content_name "] = "JavaScript相关的标题 " + i.ToString();
d3.Rows.Add(dr);
}
DataTable d4 = new DataTable();
d4.Columns.Add( "content_id ");
d4.Columns.Add( "Content_name ");
for (int i = 0; i < 10; i++)
{
DataRow dr = d4.NewRow();
dr[ "content_id "] = i;
dr[ "content_name "] = "AJAX相关的标题 " + i.ToString();
d4.Rows.Add(dr);
}
Repeater rpt = (Repeater)(e.Item.FindControl( "rpt_content "));
DataRowView drv = (DataRowView)e.Item.DataItem;
int id = Convert.ToInt32(drv[ "type_id "]); // < <======这里报错~~
switch (id)
{
case 1 :
rpt.DataSource = d2;
rpt.DataBind();
break;
case 2 :
rpt.DataSource = d3;
rpt.DataBind();
break;
case 3 :
rpt.DataSource = d4;
rpt.DataBind();
break;
}
}
虚心请教~~~~
[解决办法]
你的前台代码是什么?