我正在尝试将数组直接绑定到网格视图控件,我试图在网格视图控件上显示详细信息。
我已经尝试过以下代码,但它会抛出一些错误。请帮我找到合适的解决方案。谢谢。
代码:
protected void ddlCircle_SelectedIndexChanged(object sender, EventArgs e)
{
ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter cd;
cd = new ShadingAnalysisDataSetTableAdapters.tbl_CadEngineersTeamTableAdapter();
DataTable dt = new DataTable();
dt = cd.GetAvailableData(ddlCircle.SelectedValue);
int x, y;
DataTable dt3 = new DataTable();
dt3 = cd.GetTeam();
y = dt3.Rows.Count;
x = dt.Rows.Count;
DataTable dt2 = new DataTable();
dt2 = cd.GetAssignTeam(x);
string[] strArr = new string[dt.Rows.Count];
int i = 0;
testc:
foreach (DataRow r in dt2.Rows)
{
strArr[i] = r["Team"].ToString();
i++;
if (i >= x - 1)
{
break;
}
if (i >= y)
{
goto testc;
}
}
GridView2.DataSource = strArr[i];
GridView2.DataBind();
}
答案 0 :(得分:1)
GridView2.DataSource = strArr[i];
此行可能会产生错误,对吗?这是因为您在最后一次迭代中将i
增加到dt2.Rows.Count + 1
写这个
if (i > 0) GridView2.DataSource = strArr[i - 1];
作为最后一行。