I am writing a web application in Visual Studio 2015 pro using C# and ASP.NET. Right now, I have it set up where the user will click a button and the C# code will go get a bunch of data then display it back to the user in tables. I have spent a day of work trying to figure out how to add some form of a clickable event to the table rows but have had no success. Ultimately, what I want to do is call a method in my C# code when the table row is clicked and send it the row index.

Here is the C# code I am using for generating the tables:

    protected void searchButton_Click(object sender, EventArgs e)
            // Remove the error display
            resultListLabel.Style.Add("Display", "None");

            // Get document groups 
            groups = TableCommands.getGroups(dbConn, "retriever", searchTextOne.Text, searchTextTwo.Text);

            foreach (var dataPair in groups)
                // Get data pair group names into list
                List<string> name = dataPair.Key.Split('|').ToList();

                // ====== Make table
                Table resultTable = new Table();
                resultTable.Attributes["class"] = "displayTable";

                // ====== Add table info row
                TableRow groupInfo = new TableRow();
                groupInfo.Attributes["class"] = "groupInfoLabel";

                // add row to table

                // create cell with information
                TableCell infoCell = new TableCell();
                infoCell.Text = "MRN: "+name[0]+", Name: " + name[1];
                infoCell.ColumnSpan = 3;

                // add cell to row

                // ====== Make column label row
                TableRow labelRow = new TableRow();
                labelRow.Attributes["class"] = "columnLabel";

                // add row to table

                // make an array of column lables
                string[] cellNames = new string[] { "Visit Date", "Document Type", "Doctor ID" };

                // add column lables to row
                foreach (string s in cellNames)
                    TableCell labelCell = new TableCell();
                    labelCell.Text = s;

                // Add display names to table
                foreach(var nameList in dataPair.Value)
                    TableRow nameRow = new TableRow();
                    nameRow.Attributes["class"] = "columnInfo";

                    for (int i = 0; i < 3; i++)
                        TableCell nameCell = new TableCell();
                        nameCell.Text = nameList[i];

        catch(Exception ex)
            // Display the error and write to log
            resultListLabel.Style.Add("Display", "Inline-Block");
            writeLog("Failed to generate tables", ex.ToString());


Related posts

Recent Viewed