Reputation: 305
I created a 5x10 Matrix in c#. Now I want to retrieve these values into a 5x10 table in asp. There are only 2 possible values "Available" and "Unavailable". If the value is 1, the table cell background should show green color. If the value is 0, the table cell background should show red color. How can I achieve this? The following is the code that I have written so far to insert values into matrix from DropDownList
protected void Button1_Click(object sender, EventArgs e)
{
String[][] matrix=new String[5][];
for(int i=0;i<5;i++)
{
matrix[i]=new String[10];
}
int q=1;
for (int i = 0; i <= 4; i++)
{
for (int j = 0; j <= 9; j++)
{
DropDownList tb = this.FindControl("DropDownList" + q) as DropDownList;
matrix[i][j] = tb.SelectedItem.Text;
q++;
}
}
For retrieving these values back into a table, I am not getting an idea on how to display the cell background as green if the value is "Available" and red if the value is "Unavailable".
Upvotes: 0
Views: 2937
Reputation: 26199
you can Try this:
for(int rows=0;rows<Table1.Rows.Count;rows++)
{
for (int cols = 0; cols < Table1.Rows[rows].Cells.Count; cols++)
{
if (Convert.ToInt32(Table1.Rows[rows].Cells[cols].Text.ToString()) == 1)
{
Table1.Rows[rows].Cells[cols].BackColor = Color.Green;
}
else if (Convert.ToInt32(Table1.Rows[rows].Cells[cols].Text.ToString()) == 0)
{
Table1.Rows[rows].Cells[cols].BackColor = Color.Red;
}
}
}
Upvotes: 2