TableCell Array를 정의하려고하는데 문제가 있습니다. 나는 다음과 같은 오류 얻을 사이트에서이 작업을 실행하려고하면TableCell을 정의하고 배열로 채우시겠습니까?
public partial class ShowGoalsUserControl : UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb _web = SPContext.Current.Web;
SPList objGoalsList = _web.Lists["Goals"];
SPListItemCollection goalsItems = getItemsByQueryID(objGoalsList);
foreach (SPItem goalItem in goalsItems)
{
goalTitle.Text = "<h3>" + Convert.ToString(goalItem["Title"]) + "</h3>";
txtDescription.Text = Convert.ToString(goalItem["Description"]);
TableCell[] tc = new TableCell[9];
for (int i = 0; i < tc.Length; i++)
{
tc[i] = new TableCell();
}
tc[0].Text = "Status:";
setStatus(goalItem, tc[1], _web);
tc[2].Text = "Owner:";
SPFieldLookupValue thisOwner = getOwner(goalItem);
tc[3].Text = thisOwner.LookupValue;
tc[4].Text = "Perspective:";
SPFieldLookupValue thisPerspective = new SPFieldLookupValue(goalItem["Perspective"].ToString());
tc[5].Text = thisPerspective.LookupValue;
tc[6].Text = "Parent:";
SPFieldLookupValue thisParent = new SPFieldLookupValue(goalItem["Parent"].ToString());
tc[7].Text = thisParent.LookupValue;
tc[8].Text = "Deadline:";
tc[9].Text = Convert.ToString(goalItem["Deadline"]);
TableRow[] tr = new TableRow[4];
for (int p = 0; p < tr.Length; p++)
{
tr[p] = new TableRow();
}
setTableRow(tc[0], tc[1], tr[0]);
setTableRow(tc[2], tc[3], tr[1]);
setTableRow(tc[4], tc[5], tr[2]);
setTableRow(tc[6], tc[7], tr[3]);
setTableRow(tc[8], tc[9], tr[4]);
addToTable(tr);
}
}
SPListItemCollection getItemsByQueryID(SPList list)
{
SPQuery query = new SPQuery();
query.Query = "<Where><Eq><FieldRef Name='ID' /><Value Type='Text'>" + Request.QueryString["gid"] + "</Value></Eq></Where>";
SPListItemCollection items = list.GetItems(query);
return items;
}
void setStatus(SPItem item, TableCell status, SPWeb web)
{
string statusTest = Convert.ToString(item["Status"]);
switch (statusTest)
{
case "Approved":
status.Text = "<img src='" + web.Site.Url + "/_layouts/images/kpidefaultlarge-0.gif' height='10' width='10' />";
break;
case "Pending":
status.Text = "<img src='" + web.Site.Url + "/_layouts/images/kpidefaultlarge-1.gif' height='10' width='10' />";
break;
case "Declined":
status.Text = "<img src='" + web.Site.Url + "/_layouts/images/kpidefaultlarge-2.gif' height='10' width='10' />";
break;
}
}
SPFieldLookupValue getOwner(SPItem item)
{
SPFieldLookupValue getThisOwner = new SPFieldLookupValue(item["Owner"].ToString());
return getThisOwner;
}
void setTableRow(TableCell add1, TableCell add2, TableRow row)
{
row.Cells.Add(add1);
row.Cells.Add(add2);
}
void addToTable(TableRow[] tableRow)
{
for (int i = 0; i < tableRow.Length; i++)
{
infoTable.Rows.Add(tableRow[i]);
}
}
}
를 다음과 같이 내 코드는 다음과 같습니다
Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
내가 잘못하고있는 중이 야 무엇을? 더 좋은 방법이 있습니까? 모든 의견이 도움이 될 것입니다!
편집 : TC [3] TC에 따라 변경 [2] EDIT2 : 게시 전체 코드 루프를 위해하지 않습니다 의미에서
조건은 'i