I created a web form and dropped a table in there called resultsTable. This
also resulted in the following being added to the Webform1 class:
public System.Web.UI.WebControls.Table resultsTable;
I can easily add rows and columns via C# programming from the WebForm1
class. However I cannot figure out how I can access this control outside of
this class.
For example, I have a different class called TestResult. As I create
TestResult classes from the Page_Load event, I want the constructor of
TestResult to add rows and columns to the resultsTable. However I can't
figure out how I can access the resultsTable from my TestResult constructor.
For example:
private void Page_Load(object sender, System.EventArgs e)
{
// Generate rows and cells.
TestResult[] TestResults = new TestResult[3];
TestResults[0] = new TestResult("Mike Brown", "Pass");
TestResults[1] = new TestResult("Jill Smith", "Did not attend");
...
So then in my TestResult constructor, as I receive the name and status (i.e.
Mike Brown, Pass) I want to add a row to the table for each person and set
the cells to these values, among other things that the constructor is doing.
I imagine I can pass a reference to the testResult table but that seems a
bit messy. Is there a better way? How can I talk to the testResults table
to add these rows/columns from a class other than the class testResults
table is defined in?
Thank you.