private void InitForm()
{
try
{
// Check for license and apply if exists
string licenseFile = Server.MapPath("~/App_Data/Aspose.Total.lic");
if (File.Exists(licenseFile))
{
License license = new License();
license.SetLicense(licenseFile);
}
DataTable dataTable = null;
if (Session["AsposeDynamicFormsdataTable"] == null)
{
//Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(Server.MapPath("~/Addons/Aspose.SiteFinity.FormBuilder.ToExcel/uploads/AsposeDynamicFormsDataFile.xlsx"),
FileMode.Open, FileAccess.Read);
//Instantiating a Workbook object
//Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);
//Accessing a worksheet using its sheet name
Worksheet worksheet = workbook.Worksheets["Settings"];
//Exporting the contents of 7 rows and 2 columns starting from 1st cell to DataTable
dataTable = worksheet.Cells.ExportDataTableAsString(0, 0, worksheet.Cells.Rows.Count, 10, true);
//Closing the file stream to free all resources
fstream.Close();
dataTable.DefaultView.Sort = "[Sort ID] ASC";
dataTable = dataTable.DefaultView.ToTable();
Session["AsposeDynamicFormsdataTable"] = dataTable;
}
else
{
dataTable = (DataTable)Session["AsposeDynamicFormsdataTable"];
}
if (dataTable != null)
{
if (dataTable.Rows.Count > 0)
{
string fieldType = "Text";
int rows = 0;
foreach (DataRow row in dataTable.Rows)
{
if (!row[7].ToString().Trim().ToLower().Equals("false"))
{
rows += 1;
fieldType = row[1].ToString();
switch (fieldType)
{
case "Title":
{
lblTitle.Text = row[4].ToString().Trim();
}
break;
case "Success":
{
success_msg.InnerText = row[4].ToString().Trim();
}
break;
case "Text":
{
Label lbl = new Label();
LiteralControl table = new LiteralControl("<tr><td>");
lbl.ID = "lbl" + row[2].ToString();
lbl.Text = row[3].ToString();
lbl.Text = lbl.Text + " : ";
myPlaceHolder.Controls.Add(table);
myPlaceHolder.Controls.Add(lbl);
table = new LiteralControl("</td>");
myPlaceHolder.Controls.Add(table);
TextBox textBox = new TextBox();
textBox.ID = row[2].ToString().Trim();
textBox.Attributes.Add("placeholder", row[4].ToString().Trim());
textBox.CssClass = "myinput";
table = new LiteralControl("<td>");
if (myPlaceHolder.FindControl(textBox.ID) == null)
{
myPlaceHolder.Controls.Add(table);
myPlaceHolder.Controls.Add(textBox);
table = new LiteralControl("</td></tr>");
myPlaceHolder.Controls.Add(table);
}
}
break;
case "MultiText":
{
Label lbl = new Label();
lbl.ID = "lbl" + row[2].ToString().Trim();
LiteralControl table = new LiteralControl("<tr><td>");
lbl.Text = row[3].ToString().Trim();
lbl.Text = lbl.Text + " : ";
myPlaceHolder.Controls.Add(table);
myPlaceHolder.Controls.Add(lbl);
table = new LiteralControl("</td>");
myPlaceHolder.Controls.Add(table);
TextBox textBox = new TextBox();
textBox.ID = row[2].ToString().Trim();
textBox.Attributes.Add("placeholder", row[4].ToString().Trim());
textBox.TextMode = TextBoxMode.MultiLine;
textBox.CssClass = "myinput";
table = new LiteralControl("<td>");
if (myPlaceHolder.FindControl(textBox.ID) == null)
{
myPlaceHolder.Controls.Add(table);
myPlaceHolder.Controls.Add(textBox);
table = new LiteralControl("</td></tr>");
myPlaceHolder.Controls.Add(table);
}
}
break;
case "Radio":
{
Label lbl = new Label();
LiteralControl table = new LiteralControl("<tr><td>");
lbl.ID = "lbl" + row[2].ToString().Trim();
lbl.Text = row[3].ToString().Trim();
lbl.Text = lbl.Text + " : ";
myPlaceHolder.Controls.Add(table);
myPlaceHolder.Controls.Add(lbl);
table = new LiteralControl("</td>");
myPlaceHolder.Controls.Add(table);
int i = 0;
table = new LiteralControl("<td>");
myPlaceHolder.Controls.Add(table);
foreach (string strItem in row[2].ToString().Trim().Split(';'))
{
if (!strItem.Equals(""))
{
RadioButton radioButton = new RadioButton();
radioButton.GroupName = "RadioGroup" + rows.ToString();
if (row[4].ToString().Trim().Split(';').Length >= i)
{
radioButton.Text = row[4].ToString().Trim().Split(';')[i];
radioButton.ID = row[2].ToString().Trim().Split(';')[i];
if (i == 0)
{
radioButton.Checked = true;
}
}
if (myPlaceHolder.FindControl(radioButton.ID) == null)
{
myPlaceHolder.Controls.Add(radioButton);
}
i++;
}
}
table = new LiteralControl("</td></tr>");
myPlaceHolder.Controls.Add(table);
}
break;
case "Check":
{
Label lbl = new Label();
LiteralControl table = new LiteralControl("<tr><td>");
lbl.ID = "lbl" + row[2].ToString().Trim();
lbl.Text = row[3].ToString().Trim();
lbl.Text = lbl.Text + " : ";
myPlaceHolder.Controls.Add(table);
myPlaceHolder.Controls.Add(lbl);
table = new LiteralControl("</td>");
myPlaceHolder.Controls.Add(table);
int i = 0;
table = new LiteralControl("<td>");
myPlaceHolder.Controls.Add(table);
foreach (string strItem in row[4].ToString().Trim().Split(';'))
{
if (!strItem.Equals(""))
{
CheckBox checkBox = new CheckBox();
checkBox.Style.Add("margin-left", "2px");
if (row[4].ToString().Trim().Split(';').Length >= i)
{
checkBox.Text = row[4].ToString().Trim().Split(';')[i];
checkBox.ID = row[2].ToString().Trim().Split(';')[i];
}
if (myPlaceHolder.FindControl(checkBox.ID) == null)
{
myPlaceHolder.Controls.Add(checkBox);
}
i++;
}
}
table = new LiteralControl("</td></tr>");
myPlaceHolder.Controls.Add(table);
}
break;
case "DropDown":
{
Label lbl = new Label();
lbl.ID = "lbl" + row[2].ToString().Trim();
lbl.Text = row[3].ToString().Trim();
lbl.Text = lbl.Text + " : ";
LiteralControl table = new LiteralControl("<tr><td>");
myPlaceHolder.Controls.Add(table);
myPlaceHolder.Controls.Add(lbl);
table = new LiteralControl("</td>");
myPlaceHolder.Controls.Add(table);
DropDownList dropdownList = new DropDownList();
dropdownList.ID = row[2].ToString().Trim();
dropdownList.CssClass = "myinput";
table = new LiteralControl("<td>");
myPlaceHolder.Controls.Add(table);
foreach (string strItem in row[4].ToString().Trim().Split(';'))
{
if (!strItem.Equals(""))
{
dropdownList.Items.Add(strItem);
}
}
if (myPlaceHolder.FindControl(dropdownList.ID) == null)
{
myPlaceHolder.Controls.Add(dropdownList);
table = new LiteralControl("</td></tr>");
myPlaceHolder.Controls.Add(table);
}
}
break;
default:
break;
}
}
}
}
}
}
catch (Exception exc)
{
success_msg.Visible = false;
error_msg.Visible = true;
error_msg.InnerText = exc.Message;
}
}