ASP.NET 自定义DataTable数据
using System.Data; //DataTable
try
{
DataTable dt = new DataTable();
dt.Columns.Add("BusinessID",System.Type.GetType("System.Int32"));
dt.Columns.Add("BusinessName", System.Type.GetType("System.String"));
dt.Columns.Add("BusinessStatus", System.Type.GetType("System.Int32"));
dt.Columns.Add("BusinessLogoUrl", System.Type.GetType("System.String"));
dt.Rows.Add(new object[] { 1, "废话充值", 0, "../Images/Business/1.png" });
dt.Rows.Add(new object[] { 2, "口水缴费", 0, "../Images/Business/2.png" });
if (dt.Rows.Count > 0)
{
Repeater_Business.DataSource = dt;
Repeater_Business.DataBind();
}
else
{
Response.Write("<script>alert('dt没数据');</script>");
}
}
catch (Exception ex)
{
Response.Write("Error:" + ex.Message.ToString());
}
}
PS:
dt.Columns.Add("BusinessID",System.Type.GetType("System.Int32"));
写成 ->
dt.Columns.Add("BusinessID",System.Type.GetType("System.Int"));
后面的Int32
改成Int
,可能会出现这样的Error:
“dataType”参数不能为空。参数名: dataType