Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

It's been many years since I've messed with the web... I like to stay on desktops... ASP.NET has been fun to learn thus far... all positive changes from ASP and the learning curve isn't too bad. I have a friend who has a theory of if it works who cares what the code looks like... I care. I like doing things 'best practice'. This web site I'm working on is for a church... this page will dynamically display upcoming events from the database in a table where the first row has two columns (Title and Date) the second row is a description, and the third row is for Edit/Delete. Then the next event would take the next three rows... you get the idea. To me, what I have below is simple and works great, but, people with experiance may tell me I'm doing things the hard way or picking up bad practices... so input please.

 

 //Get the events - not sorting by time yet...
             SqlCommand myCmd = new SqlCommand("SELECT * FROM Events ORDER BY eventDateTime", myDB.sqlConn);
             SqlDataReader sdr = myCmd.ExecuteReader();
             while(sdr.Read())
             {
                 //Add new row for Title and Date
                 int row = this.EventTable.Rows.Add(new TableRow());
                 //Add cell for Title
                 this.EventTable.Rows[row].Cells.Add(new TableCell());
                 //Add Title
                 this.EventTable.Rows[row].Cells[0].Text = sdr["eventTitle"].ToString();
                 //Make Title Bold
                 this.EventTable.Rows[row].Cells[0].Font.Bold = true;
                 //Add cell for Date
                 this.EventTable.Rows[row].Cells.Add(new TableCell());
                 //HorizontalAlign="Right"
                 this.EventTable.Rows[row].Cells[1].HorizontalAlign = HorizontalAlign.Right;
                 //Add Date
                 this.EventTable.Rows[row].Cells[1].Text = sdr["eventDateTime"].ToString();
                 //Make the row a color of some sort
                 this.EventTable.Rows[row].BackColor = Color.PaleGoldenrod;
                 //Make Date Bold
                 this.EventTable.Rows[row].Cells[1].Font.Bold = true;
                 //Add new row for Description
                 row = this.EventTable.Rows.Add(new TableRow());
                 //Add cell for Description and Merge
                 this.EventTable.Rows[row].Cells.Add(new TableCell());
                 this.EventTable.Rows[row].Cells[0].ColumnSpan = 2;
                 //Add Description
                 this.EventTable.Rows[row].Cells[0].Text = sdr["eventText"].ToString();
                 //Add new row for Edit and Delete
                 row = this.EventTable.Rows.Add(new TableRow());
                 //Add cell for these two and Merge, align right;
                 this.EventTable.Rows[row].Cells.Add(new TableCell());
                 this.EventTable.Rows[row].Cells[0].ColumnSpan = 2;
                 this.EventTable.Rows[row].Cells[0].HorizontalAlign = HorizontalAlign.Right;
                 //Add Edit and Delete
                 string Edit = "<a href=\"EditEvent.aspx?id=" + sdr["ID"] + "\">Edit</a>";
                 string Delete = "<a href=\"DeleteEvent.aspx?id=" + sdr["ID"] + "\">Delete</a>";
                 //Add hyperlinks to the cell
                 this.EventTable.Rows[row].Cells[0].Text = Edit + " " + Delete;
}
 

 

By the way does anyone have any idea when they're going to get the code to display right like it use to?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...