Member Avatar for kyeong
kyeong

This loop is suppose to re-color every button that's on top and to the right of the clicked button. I can have it work on one column or one row, but when I try to get it to work on more than one row and/or column, this exception is thrown at me. I'm trying different ways and always get the NullReferenceException error message.

protected void button_Click(object sender, EventArgs e)
    {
        Button button = (Button)sender;
        int row = int.Parse(btn.ID.Substring(6, 1));
        int col = int.Parse(btn.ID.Substring(7, 1));
        int j = row;
        int k = col;

        for (int i = 0; 0 < j; i++)
        {
            String stringID = "btn" + j.ToString() + k.ToString();
            Button b = (Button)FindControl(stringID);

            b.BackColor = System.Drawing.Color.White;  // ERROR OCCURS HERE
            b.BorderStyle = System.Web.UI.WebControls.BorderStyle.None;
            b.Enabled = false;

            j--;

            if (j == 0)
            {
                k++;
                j = row;
            }
        }

I can't even find out if this loop works because of the error.

Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.