Creating table header using C# - c#

I am trying to create table like spreadsheet using asp.net C# table to use it as timesheet
right now I can create table numberOFDayInMonth X 4 cols. I need some help in how to add header name and text box control to table dynamically?? could someone help me ??
my C# code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
namespace Compudata_ProjectManager
{
public partial class testPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DateTimeFormatInfo info = DateTimeFormatInfo.GetInstance(null);
for (int i = 1; i < 13; i++)
{
//Response.Write(info.GetAbbreviatedMonthName(i) + "<br />");
ddl_months.Items.Add(new ListItem(info.GetMonthName(i), i.ToString()));
}
}
}
protected void ddl_months_SelectedIndexChanged(object sender, EventArgs e)
{
// Remove all the current rows and cells.
// This is not necessary if EnableViewState is set to false.
tbl_timesheet.Controls.Clear();
//declare datetime dt
DateTime dt = new DateTime();
int orderOfMonth = Convert.ToInt32(ddl_months.SelectedValue.ToString());
//get number of date in X month
int noOfDays = DateTime.DaysInMonth(dt.Year, orderOfMonth);
int numOfCols = 4;
for (int row = 0; row < noOfDays; row++)
{
// Create a new TableRow object.
TableRow rowNew = new TableRow();
// Put the TableRow in the Table.
tbl_timesheet.Controls.Add(rowNew);
for (int col = 0; col < numOfCols; col++)
{
// Create a new TableCell object.
TableCell cellNew = new TableCell();
cellNew.Text = "Example Cell (" + row.ToString() + ",";
cellNew.Text += col.ToString() + ")";
// Put the TableCell in the TableRow.
rowNew.Controls.Add(cellNew);
}
}
}
}
}

for headerrow and Dynamic TextBox control
Table tbl = new Table(); // Creating a new table
TableHeaderRow header = new TableHeaderRow(); // Creating a header row
tbl.Rows.Add(header); // Add the header row to table tbl
// Creating Dynamic TextBox Control
TextBox t = new TextBox();
t.ID = "myTextBox"; // assing an ID
// Now add this in a table row
TableRow rowNew = new TableRow(); // Creating a new table row
rowNew.Cells[0].Controls.Add(t); // add the textbox control at cell zero
// or you can add it as
rowNew.Controls.Add(t);

Related

Get Data From Excel only shows last row

I'm having some issues ASPxGridView on Getting data from Excel file. It's only showing the last data from Excel. I've tried to create custom unbound but got no luck. Tried to make it to the List<> and give it a try, no success. This is my code so far.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using DevExpress.Spreadsheet;
using DevExpress.Spreadsheet.Export;
using System.Data;
string FilePath
{
get { return Session["FilePath"] == null ? String.Empty : Session["FilePath"].ToString(); }
set { Session["FilePath"] = value; }
}
private DataTable GetTableFromExcel()
{
Workbook book = new Workbook();
book.InvalidFormatException += book_InvalidFormatException;
book.LoadDocument(FilePath);
Worksheet sheet = book.Worksheets.ActiveWorksheet;
Range range = sheet.GetUsedRange();
DataTable table = sheet.CreateDataTable(range, false);
DataTableExporter exporter = sheet.CreateDataTableExporter(range, table, false);
exporter.CellValueConversionError += exporter_CellValueConversionError;
exporter.Export();
return table;
}
void book_InvalidFormatException(object sender, SpreadsheetInvalidFormatExceptionEventArgs e)
{
}
void exporter_CellValueConversionError(object sender, CellValueConversionErrorEventArgs e)
{
e.Action = DataTableExporterAction.Continue;
e.DataTableValue = null;
}
protected void Upload_FileUploadComplete(object sender, DevExpress.Web.FileUploadCompleteEventArgs e)
{
FilePath = Page.MapPath("~/XlsTables/") + e.UploadedFile.FileName;
e.UploadedFile.SaveAs(FilePath);
}
public class invoice
{
public string nomor_invoice { get; set; }
}
protected void Grid_CustomCallback(object sender, DevExpress.Web.ASPxGridViewCustomCallbackEventArgs e)
{
if (!String.IsNullOrEmpty(FilePath))
{
DataTable table = GetTableFromExcel(); // Get The Excel
List<object> inv = new List<object>();
List<object> dekl = new List<object>();
List<invoice> invoiceList = new List<invoice>();
for (int i = 1; i < table.Rows.Count; i++)
{
DataRow row = table.Rows[i];
invoice nomorInvo = new invoice();
nomorInvo.nomor_invoice = row[1].ToString();
invoiceList.Add(nomorInvo);
string noDkl = row[0].ToString().ToUpper().Trim();
string[] nomor = noDkl.Split('-');
Decimal cab = decimal.Parse(nomor[0].ToString());
Decimal pmsrn = decimal.Parse(nomor[1].ToString());
Decimal reg = decimal.Parse(nomor[2].ToString());
string dkl = nomor[3].ToString();
Decimal cob = decimal.Parse(nomor[4].ToString());
Decimal bln = decimal.Parse(nomor[5].ToString());
Decimal thn = decimal.Parse(nomor[6].ToString());
string invo_no = row[1].ToString().Trim();
inv.Add(invo_no); // add to the list
inv.ToList();
SSREAS.DL.AE.Upload.dsImportir.APFDPE17Row invc = new DL.AE.Upload.dsImportirTableAdapters.APFDPE17TableAdapter().GetDataByDkinvc(cab, pmsrn, reg, dkl, cob, bln, thn, invo_no).SingleOrDefault();
// This is my select query. I used dataSet
if (invc != null)
{
for (int z = 0; z < inv.Count; z++)
{
odsGrid.SelectParameters["DKKDCB"].DefaultValue = cab.ToString();
odsGrid.SelectParameters["DKKDPS"].DefaultValue = pmsrn.ToString();
odsGrid.SelectParameters["DKRGDK"].DefaultValue = reg.ToString();
odsGrid.SelectParameters["DKDKL"].DefaultValue = dkl;
odsGrid.SelectParameters["DKCOB"].DefaultValue = cob.ToString();
odsGrid.SelectParameters["DKBLN"].DefaultValue = bln.ToString();
odsGrid.SelectParameters["DKTHN"].DefaultValue = thn.ToString();
odsGrid.SelectParameters["DKINVC"].DefaultValue = invo_no;
Grid.DataBind();
}
}
else if (invc == null)
{
return;
}
Grid.DataBind();
}
}
}
I've set breakpoint and 0 error occured, But when I upload the Excel File, It's show only 1 data instead of 2 and its the last row from excel. What is wrong with my code? A help would be appreciated. Thanks!
Persist the table in the cache or session in the page_prerender() event bind the data it will work.

c# - DataGridView add row runtime error cell's model

I have a DataGridView component that I use to show some value to the user. It is made of 5 columns: 4 strings and 1 check box. This is my code to create columns and add them to the conrtol:
// class variables
const int NUM_COLUMNS = 5;
DataGridViewColumn[] columns;
DataGridViewCheckBoxColumn checkColumn;
List <String> columnsHeaderName;
// init method
private void init_dataGridView()
{
// init all components
columnsHeaderName = new List<string>();
columns = new DataGridViewColumn[NUM_COLUMNS - 1]; // minus one becouse last one is a check box column
checkColumn = new DataGridViewCheckBoxColumn(); // last one
// columns descriptions
columnsHeaderName.Add("File path");
columnsHeaderName.Add("Sampling");
columnsHeaderName.Add("Start Date");
columnsHeaderName.Add("End Date");
columnsHeaderName.Add("Select");
for (int i = 0; i < NUM_COLUMNS - 1; i++)
{
// create, configure and add n-1 columns
columns[i] = new DataGridViewColumn();
columns[i].Name = Convert.ToString(i);
columns[i].HeaderText = columnsHeaderName[i];
columns[i].ReadOnly = true;
this.dataGridView1.Columns.Add(columns[i]);
}
// create, configure and add last column
checkColumn.Name = Convert.ToString(NUM_COLUMNS - 1);// (NUM_COLUMNS - 1).ToString();
checkColumn.HeaderText = columnsHeaderName[NUM_COLUMNS - 1];
checkColumn.Width = 50;
checkColumn.ReadOnly = false;
checkColumn.FillWeight = 10; //if the datagridview is resized (on form resize) the checkbox won't take up too much; value is relative to the other columns' fill values
this.dataGridView1.Columns.Add(checkColumn);
}
The problem appears when I try to add a new row to my table
private void LoadFileButton_Click(object sender, EventArgs e)
{
string file = "";
DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
if (result == DialogResult.OK) // Test result.
{
file = openFileDialog1.FileName;
Console.WriteLine(file);
dataGridView1.Rows.Add(new object[] { "value 1", "value 2", "value 3", "value 4", true });
}
}
The call to dataGridView1.Rows.Add() method throws me an exception. The description of the exception is: "At least one of the columns has not any cell's model"
Really I don't understand what I am doing wrong. Hope some ine can help me. Thanks in advance.
You cannot add DataGridViewColumn
If you try and run below code:
DataGridViewTextBoxColumn col = new DataGridViewTextBoxColumn();
col.Name = "xyz";
col.HeaderText = "XYZ";
col.ReadOnly = true;
this.dataGridView1.Columns.Add(col);
It will work because we are adding DataGridViewTextBoxColumn not DataGridViewColumn
So possible fix is
for (int i = 0; i < NUM_COLUMNS - 1; i++)
{
// create, configure and add n-1 columns
columns[i] = new DataGridViewTextBoxColumn(); // or some other type that you want
columns[i].Name = Convert.ToString(i);
columns[i].HeaderText = columnsHeaderName[i];
columns[i].ReadOnly = true;
this.dataGridView1.Columns.Add(columns[i]);
}
Try this
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace stackkcw
{
public partial class Form1 : Form
{
public TcpClient client;
private DataGridView datgdStock;
private TextBox lablUpdates;
private TextBox lablTime;
private int countOfData;
DataTable dt = new DataTable();
public Form1()
{
InitializeComponent();
init_dataGridView();
}
const int NUM_COLUMNS = 5;
DataGridViewColumn[] columns;
DataGridViewCheckBoxColumn checkColumn;
List<String> columnsHeaderName;
// init method
private void init_dataGridView()
{
dt.Columns.Add("File path", typeof(string));
dt.Columns.Add("Sampling", typeof(decimal));
dt.Columns.Add("Start Date", typeof(DateTime));
dt.Columns.Add("End Date", typeof(DateTime));
dt.Columns.Add("Select", typeof(Boolean));
dt.Rows.Add(new object[] { "c:\\", 123.45, DateTime.Parse("1/1/2017"), DateTime.Parse("1/2/2017"), true });
dt.Rows.Add(new object[] { "c:\\", 123.46, DateTime.Parse("1/8/2017"), DateTime.Parse("1/9/2017"), false });
dt.Rows.Add(new object[] { "c:\\", 123.47, DateTime.Parse("1/15/2017"), DateTime.Parse("1/16/2017"), true });
dt.Rows.Add(new object[] { "c:\\", 123.48, DateTime.Parse("1/22/2017"), DateTime.Parse("1/23/2017"), false });
dt.Rows.Add(new object[] { "c:\\", 123.49, DateTime.Parse("1/29/2017"), DateTime.Parse("1/30/2017"), true });
dataGridView1.DataSource = dt;
}
}
}

In GridView Header Row DropDownList to select header column mapping

I Created a application which will map the data and save the Data fields. For that first row in my GridView I added new HearerRow with dropdownlist.
Below is my code which I have attached.
My HTML Page code:
<asp:GridView ID="gvDataMapping" runat="server" AutoGenerateColumns="false">
</asp:GridView>
And Code Behind:
for (int i = 0; i < dtValues.Columns.Count; i++)
{
BoundField boundfield = new BoundField();
boundfield.DataField = dtValues.Columns[i].ColumnName.ToString();
boundfield.HeaderText = dtValues.Columns[i].ColumnName.ToString();
gvDataMapping.Columns.Add(boundfield);
}
gvDataMapping.DataSource = dtValues;
gvDataMapping.DataBind();
GridViewRow HeaderGridRow = new GridViewRow(0, 0, DataControlRowType.Header,
DataControlRowState.Insert);
DropDownList ddlFieldValues;
TableCell HeaderCell;
foreach (DataColumn dc in dtValues.Columns)
{
ddlFieldValues = new DropDownList();
ddlFieldValues.ID = "FieldValues";
ddlFieldValues.DataSource = (DataTable)Session["WorkItemTypeField"];
ddlFieldValues.DataTextField = "FieldName";
ddlFieldValues.DataValueField = "FieldID";
ddlFieldValues.DataBind();
ddlFieldValues.Items.Insert(0, new ListItem("", "0"));
HeaderCell = new TableCell();
HeaderCell.Controls.Add(ddlFieldValues);
HeaderGridRow.Cells.Add(HeaderCell);
}
gvDataMapping.DataSource = dtValues;
gvDataMapping.DataBind();
gvDataMapping.Visible = true;
lblDataMapping.Visible = true;
gvDataMapping.Controls[0].Controls.AddAt(1, HeaderGridRow);
See the Click here to view screen displays the output of above code . While clicking Save am not getting the GridView Header DropDowmList its showing null using below code.
GridViewRow gvrow2 = gvDataMapping.HeaderRow;
foreach (GridViewRow row in gvDataMapping.Rows)
{
for (int i = 0; i < gvDataMapping.Columns.Count; i++)
{
String header = gvDataMapping.Columns[i].HeaderText; //gets column name
DropDownList cellText = ((DropDownList)gvrow2.Cells[i].FindControl("FieldValues")); //Not getting the DDL returns null
}
}
How to get the GridView Header row dropdownlist values in Save click event?
No guarantees, because I haven't tried this myself, but what about this code?
GridViewRow gvrow1 = GrdDynamic1.HeaderRow;
foreach (GridViewRow row in GrdDynamic1.Rows)
{
for (int i = 0; i < GrdDynamic1.Columns.Count; i++)
{
String header = GrdDynamic1.Columns[i].HeaderText;
DropDownList cellText = ((DropDownList)gvrow1.Cells[i].FindControl("FieldValues"));
}
}
It looks as if you're looking for the drop down list in the right column, but not the right row: you're looking in the data row, rather than the header row gvrow1.

Selecting a dynamically created table row in ASP.NET with C#

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)
{
try
{
// 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";
resultList.Controls.Add(resultTable);
// ====== Add table info row
TableRow groupInfo = new TableRow();
groupInfo.Attributes["class"] = "groupInfoLabel";
// add row to table
resultTable.Rows.Add(groupInfo);
// create cell with information
TableCell infoCell = new TableCell();
infoCell.Text = "MRN: "+name[0]+", Name: " + name[1];
infoCell.ColumnSpan = 3;
// add cell to row
groupInfo.Cells.Add(infoCell);
// ====== Make column label row
TableRow labelRow = new TableRow();
labelRow.Attributes["class"] = "columnLabel";
// add row to table
resultTable.Rows.Add(labelRow);
// 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;
labelRow.Cells.Add(labelCell);
}
// 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];
nameRow.Cells.Add(nameCell);
}
resultTable.Rows.Add(nameRow);
}
}
}
catch(Exception ex)
{
// Display the error and write to log
resultListLabel.Style.Add("Display", "Inline-Block");
writeLog("Failed to generate tables", ex.ToString());
}
}
Here's what I had to do:
Add a global boolean to called tableCall to the C# code
Move the code in searchButton_Click into an if(tableCall) statement in the Page_Load method.
protected void Page_Load(object sender ,EventArgs e){
...
if(tableCall){
//Do stuff from searchButton_Click
}
...
}
Add tableCall = true; and Page_Load(sender, e) to searchButton_Click
Modify the for loop to add buttons in the cell like so:
// Add display names to table
foreach (var nameList in dataPair.Value)
{
TableRow nameRow = new TableRow();
nameRow.Attributes["class"] = "columnInfo";
// 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();
nameRow.Cells.Add(nameCell);
Button b = new Button();
b.Attributes["class"] = "docButton";
b.Attributes.Add("DWdocid", nameList[3]);
b.Text = nameList[i];
b.Click += new EventHandler((s, ea) => test(s, ea, b.Attributes["DWdocid"]));
nameCell.Controls.Add(b);
}
resultTable.Rows.Add(nameRow);
}
This adds a button to each of the three cells in the row, but adds the same document id to each of the buttons in that row, so anywhere the user clicks on that row (except for the 1px borders) will call a method in the C# code while passing it the document ID. I'm sure that with better css skills somebody could make the button span all three cells.

Need to build table in 3 columns

Edit for clarity: I know the code has 2 columns, one for title and one for date, I am trying to change the code so it displays 3 events per row.
I am new to development and I am trying to take an ASP control used in a Sitefinity 6.1 website that currently takes data from our SQL database and outputs it into a single column and instead produce an output in 3 columns.
The .ascx looks like this
<div style="margin:10px">
<asp:MultiView ID="mvEvents" runat="server" ActiveViewIndex="0">
<asp:View ID="viewDefault" runat="server">
<asp:Table ID="tblEvents" runat="server" CellPadding="5">
</asp:Table>
</asp:View>
<asp:View ID="viewList" runat="server">
<asp:Table ID="tblEventsList" runat="server" CellPadding="5">
</asp:Table>
</asp:View>
</asp:MultiView>
</div>
The PageLoad and BuildEvents portions of the .ascx.cs code look like this
protected void Page_Load(object sender, EventArgs e)
{
try
{
CalendarDataContext db = new CalendarDataContext();
var evt = db.CalendarEvents(NumberToDisplay, Department);
foreach (CalendarEventsResult Evt in evt)
{
if (Department == "List")
{
BuildEventsList(Evt.event_name, Evt.event_start_date, Evt.event_idn, Evt.information_id);
}
else
{
BuildEvents(Evt.event_name, Evt.event_start_date, Evt.event_idn, Evt.information_id);
}
}
return;
}
catch(Exception ex)
{
}
}
protected void BuildEvents(string EvtTitle, DateTime EvtStart, int EvtIdn, int EvtInfoIdn)
{
//EvtInfoIdn shows Event Description without location. EvtInfoIdn - 1 shows location information. changing the href to eventInfoId
int EvtInfoId = EvtInfoIdn - 1;
TableRow tr = new TableRow();
tr.VerticalAlign = VerticalAlign.Top;
tr.HorizontalAlign = HorizontalAlign.Center;
TableCell tcTitle = new TableCell();
TableCell tcStart = new TableCell();
StringBuilder sb = new StringBuilder();
sb.AppendLine(ShortMonth(EvtStart.Month));
sb.AppendLine(EvtStart.Day.ToString());
tr.VerticalAlign = VerticalAlign.Bottom;
tr.Height = Unit.Pixel(80);
Literal litDate = new Literal();
litDate.Text = "<div class='EventDate'>" + sb.ToString() + "</div>";
tcStart.Controls.Add(litDate);
Literal litTitle = new Literal();
litTitle.Text = #"<div class='EventTitle'><a style='text-decoration:none;' href='http://events.website.edu/EventList.aspx?view=EventDetails&eventidn=" + EvtIdn.ToString().Trim() + "&information_id=" + EvtInfoId + "&type=&rss=rss'>";
litTitle.Text = litTitle.Text + EvtTitle + "</a></div>";
tcTitle.Controls.Add(litTitle);
tr.Cells.Add(tcStart);
tr.Cells.Add(tcTitle);
tblEvents.Rows.Add(tr);
}
I have tried adding a ColumnSpan = "3" attribute to the ascx file and also tried adding the ColumnSpan to tcStart and tcTitle in the cs file as well in addition to trying to redesign the ascx in design mode and nothing I have though of has worked. I realize this is likely an easy fix, but I am new to C# programming. I appreciate any help provided.
Try the following -- n.b. I haven't been able to test fully as I haven't mocked up your bespoke classes, e.g. CalendarDataContext.
The basic premise is that the CalandarEvents collection is processed in batches of 3 (or whatever number you choose) and that the BuildEvents method now is broken down into smaller parts, each with their own responsibility, which should help with maintenance going forward.
protected void Page_Load(object sender, EventArgs e)
{
try
{
CalendarDataContext db = new CalendarDataContext();
var evt = db.CalendarEvents(NumberToDisplay, Department);
if (Department == "List")
{
foreach (CalendarEventsResult cer in evt)
{
BuildEventsList(cer.event_name, cer.event_start_date, cer.event_idn, cer.information_id);
}
}
else
{
// Depending what type evt is may depend on how to convert to the List.
// This assumes that it supports IEnumerable (like DataTable)
List<CalendarEventsResult> events = evt.AsEnumerable().ToList();
// Rather than hard-coding, read this from config or database
// to allow easier changing to a different number of events per row?
int numberOfEventsPerRow = 3;
// loop increments in steps of 3 (numberOfEventsPerRow)
for (int rowNumber = 0; rowNumber < events.Count; rowNumber += numberOfEventsPerRow)
{
// use Linq to pick out the subset of Events to process
List<CalendarEventsResult> queryEvents = events
.Skip(numberOfEventsPerRow * rowNumber)
.Take(numberOfEventsPerRow).ToList<CalendarEventsResult>();
// Build a row using that subset
TableRow tr = buildRow(queryEvents, numberOfEventsPerRow);
// Add it to the table
tblEvents.Rows.Add(tr);
}
}
}
catch (Exception ex)
{
// this just suppresses any exceptions. Better to fix issues at source.
}
}
private TableRow buildRow(List<CalendarEventsResult> events, int eventsPerRow)
{
TableRow tr = new TableRow();
// Can these be added to CSS?
tr.HorizontalAlign = HorizontalAlign.Center;
tr.VerticalAlign = VerticalAlign.Bottom;
tr.Height = Unit.Pixel(80);
TableCell tc;
// for our event subset, build a pair of cells for each Event,
// adding them to a row
foreach (var evt in events)
{
tc = BuildEventDate(evt);
tr.Cells.Add(tc);
tc = BuildEventTitle(evt);
tr.Cells.Add(tc);
}
// If we're dealing with a partial row, i.e. only 1 or 2 Events,
// pad the row with empty cells.
if (events.Count < eventsPerRow)
{
tc = BuildEmptyCell(eventsPerRow - events.Count);
tr.Cells.Add(tc);
}
return tr;
}
private TableCell BuildEventDate(CalendarEventsResult evt)
{
TableCell tc = new TableCell();
Literal litDate = new Literal();
//String.Format should suffice c.f. StringBuilder
litDate.Text = String.Format("<div class='EventDate'>{0}{1}</div>", ShortMonth(evt.Month), evt.Day.ToString());
tc.Controls.Add(litDate);
return tc;
}
private TableCell BuildEventTitle(CalendarEventsResult evt)
{
TableCell tc = new TableCell();
int evtInfoId = evt.information_id - 1;
Literal litTitle = new Literal();
// n.b. hard-coded URL doesn't look good for ease of maintenance (move to config or CalendarEventsResult?)
litTitle.Text = String.Format(#"<div class='EventTitle'><a style='text-decoration:none;' href='http://events.website.edu/EventList.aspx?view=EventDetails&eventidn={0}&information_id={1}&type=&rss=rss'>{2}</a></div>",
evt.event_idn.ToString().Trim(), evtInfoId, evt.event_name);
tc.Controls.Add(litTitle);
return tc;
}
private TableCell BuildEmptyCell(int numberOfEvents)
{
// Define as const rather than having unexplained "2" hard-coded.
const int spanPerEvent = 2;
TableCell tc = new TableCell();
tc.ColumnSpan = spanPerEvent * numberOfEvents;
tc.Text = "";
return tc;
}
}

Categories

Resources