Trying to use Access Db fields to evaluate and populate C# for dynamic table rendering

Last post 09-01-2009 9:46 AM by jlamar. 3 replies.

Sort Posts:

  • Trying to use Access Db fields to evaluate and populate C# for dynamic table rendering

    08-30-2009, 12:41 AM
    • Member
      point Member
    • jlamar
    • Member since 08-30-2009, 12:34 AM
    • Posts 3

    I am dynamically creating a table which will display an image in the background and a semi-transparent color over areas that are relevant to the image. I need to evaluate DB content against counters inside my code so as to be able to insert hyperlinks and images only on areas that are affected.

    Here is a sample of my code.

    protected void Button1_Click(object sender, EventArgs e)
        {
            int rowCount;
            int cellCount;
            int j = 0;
            int i = 0;
            for (rowCount = 0; rowCount < 3; rowCount++)
            {
                j++;
                TableRow r = new TableRow();
                for (cellCount = 0; cellCount < 3; cellCount++)
                {
    
                    i++;
                    TableCell c = new TableCell();
                    c.Controls.Add(new LiteralControl("<a href='default.aspx' target='_blank'><img src='images/active-sm.png' alt='' style='border:0;' /></a>"));
                    r.Cells.Add(c);
                }
                Table1.Rows.Add(r);
            }
    
        }

    The conditional processing would occur when using the LiteralControl. I need to evaluate and insert table data.

  • Re: Trying to use Access Db fields to evaluate and populate C# for dynamic table rendering

    08-30-2009, 2:52 AM

    So what's the problem?


    Regards Mike
    [MVP - ASP/ASP.NET]
    My site
    What ASP.NET can and can't do
  • Re: Trying to use Access Db fields to evaluate and populate C# for dynamic table rendering

    08-31-2009, 2:40 PM
    • Member
      point Member
    • jlamar
    • Member since 08-30-2009, 12:34 AM
    • Posts 3

    Here is a better example of what I am trying to do. Keep in mind that I did use the correct syntax in the code below. It is meant to be human readable. The variables with DataField are meant to be pulled from the DataSource.

    protected void Button1_Click(object sender, EventArgs e)
        {
            int rowCount;
            int cellCount;
            int j = 0;
            int i = 0;
            for (rowCount = 0; rowCount < 3; rowCount++)
            {
                j++;
                TableRow r = new TableRow();
                for (cellCount = 0; cellCount < 3; cellCount++)
                {
    
                    i++;
                    TableCell c = new TableCell();
                    //I am unsure of the following syntax in C#, but I am looking to use logic below. Read as human readable text.
                    if (DataFieldColumnID = cellCount and DataFieldRowID = rowCount)
                    {
                        c.Controls.Add(new LiteralControl("<a href='default.aspx?urlParam=DataFieldurlParam' target='_blank'><img src='images/ACTIVE.png' alt='' style='border:0;' /></a>"));
                    }
                    else
                    {
                        c.Controls.Add(new LiteralControl("<img src='images/INACTIVE.png' alt='' style='border:0;' />"));
                    }
                    }
                    r.Cells.Add(c);
                }
                Table1.Rows.Add(r);
            }
    
        }


    I hope this makes a little more sense.

    Thanks

  • Re: Trying to use Access Db fields to evaluate and populate C# for dynamic table rendering

    09-01-2009, 9:46 AM
    Answer
    • Member
      point Member
    • jlamar
    • Member since 08-30-2009, 12:34 AM
    • Posts 3

    I solved my own problem (sort of), but here is a look for anyone else. It's obviously in VB instead of C#, but it works great. There is a datagrid on the main page with an ID of MyDataGrid, which is what you see referenced twice in the script. The Datagrid is also hidden to show just the dynamically created table, but I think I might end up using the datagrid as well. This dynamically creates a table that shows a semi-transparent color over the top of a background table image showing active or affected areas of the image. I have also built an admin page which allows users to simply hover over any part of the image and click to add new reports and active cells. ENJOY!

            Dim RowID As Integer = 0
            Dim ActiveCell As Integer = 0
            Dim ColID As Integer = 0
            Dim SpecialID As Integer = 0
            Dim rows As Integer = 24
            Dim cells As Integer = 20
            Dim j As Integer = 0
            Dim i As Integer = 0
            Dim intRows As Integer = MyDataGrid.Items.Count - 1
    
            Dim GridItem As DataGridItem
    
            For j = 0 To rows - 1
    
                Dim r As New TableRow()
    
                For i = 0 To cells - 1
    
                    Dim c As New TableCell()
    
                    ' Is the current row active?
                    ' Iterate over the records returned in the datagrid
                    While intRows >= 0
    
                        GridItem = MyDataGrid.Items(intRows)
                        SpecialID = GridItem.Cells(0).Text().Trim()
                        RowID = GridItem.Cells(5).Text().Trim()
                        ColID = GridItem.Cells(6).Text().Trim()
    
                        If RowID = j And ColID = i Then
                            ActiveCell = 1
                            intRows = -1
                        End If
    
                        intRows = intRows - 1
    
                    End While
    
                    ' ACTIVE
                    If ActiveCell = 1 Then
    
                        c.Controls.Add(New LiteralControl("<a onClick='showPopup(this.href);return(false);' href='details.aspx?SpecialID=" & SpecialID & "'><img src='images/active-sm.png' alt='' style='border:0;' /></a>"))
                    ' NOT ACTIVE
                    Else
    
                        c.Controls.Add(New LiteralControl("<img src='images/inactive.png' alt='' style='border:0;' />"))
    
                    End If
    
                    r.Cells.Add(c)
                    intRows = TopView.Items.Count - 1
                    ActiveCell = 0
    
                Next
    
                Table1.Rows.Add(r)
    
            Next


Page 1 of 1 (4 items)