locked
Bug Found + Fix RRS feed

  • Question

  • User-1639143169 posted
     Here is an error... below it i have a fix....

    Server Error in '/configtest' Application.

    Attempted to divide by zero.

    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.DivideByZeroException: Attempted to divide by zero.

    Source Error:

    Line 154:                    for (int iItem = 0; iItem < dataList.Items.Count; iItem++)
    Line 155:                    {
    Line 156:                        int nRow = iItem / dataList.RepeatColumns;
    Line 157:                        int nCol = iItem % dataList.RepeatColumns;
    Line 158:                        int nDesiredIndex = iItem;


    Source File: C:\Documents and Settings\Jonathan\Desktop\wwAppConfiguration\wwAppConfiguration\UI\WebControls\Adapters\DataListAdapter.cs    Line: 156

     

    This is the if around this.... and the replacement code (for me line 146-207)

    The key to the problem is the repeatcolumns when= 0 there was no checking for this... so i made a simple bool

    bool haveItems = (dataList.RepeatColumns > 0) ? true : false;

    and everywhere that used repeaatcolkms, i but an haveItems && so that the boolean check is first.

    if (dataList.ItemTemplate != null)

    {

    writer.WriteLine();

    writer.WriteBeginTag("tbody");

    writer.Write(HtmlTextWriter.TagRightChar);

    writer.Indent++;

    int nItemsInColumn = (int)Math.Ceiling(((Double)dataList.Items.Count) / ((Double)dataList.RepeatColumns));

    bool haveItems = (dataList.RepeatColumns > 0) ? true : false;

    for (int iItem = 0; iItem < dataList.Items.Count; iItem++)

    {

    int nRow = (haveItems) ? (iItem / dataList.RepeatColumns) : 0;

    int nCol = (haveItems) ? (iItem % dataList.RepeatColumns) : 0;

    int nDesiredIndex = iItem;

    if (dataList.RepeatDirection == RepeatDirection.Vertical)

    {

    nDesiredIndex = (nCol * nItemsInColumn) + nRow;

    }

    if (haveItems && (iItem % dataList.RepeatColumns) == 0)

    {

    writer.WriteLine();

    writer.WriteBeginTag("tr");

    writer.Write(HtmlTextWriter.TagRightChar);

    writer.Indent++;

    }

    writer.WriteLine();

    writer.WriteBeginTag("td");

    writer.Write(HtmlTextWriter.TagRightChar);

    writer.Indent++;

    foreach (Control itemCtrl in dataList.Items[iItem].Controls)

    {

    itemCtrl.RenderControl(writer);

    }

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("td");

    if (haveItems && ((iItem + 1) % dataList.RepeatColumns) == 0)

    {

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("tr");

    }

    }

    if (haveItems && (dataList.Items.Count % dataList.RepeatColumns) != 0)

    {

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("tr");

    }

    writer.Indent--;

    writer.WriteLine();

    writer.WriteEndTag("tbody");

    }

    Saturday, May 27, 2006 1:00 AM

All replies