protected void FillTable() { VehicleTypeData vehicleTypeData = new VehicleTypeData(); //Populating a DataTable from database. DataTable dt = vehicleTypeData.DataTableAllVehicleType(); //Building an HTML string. StringBuilder html = new StringBuilder(); //Building the Header row. html.Append("<tbody>"); html.Append("<tr>"); foreach (DataColumn column in dt.Columns) { html.Append("<th>"); html.Append(column.ColumnName); html.Append("</th>"); } html.Append("</tr>"); //Building the Data rows. foreach (DataRow row in dt.Rows) { html.Append("<tr class='desmarcado'>"); foreach (DataColumn column in dt.Columns) { html.Append("<td onclick='getValue(this.parentNode)' style='cursor:pointer'>"); html.Append(row[column.ColumnName]); html.Append("</td>"); } html.Append("<td>"); html.Append("<button onclick='setValues(this.parentNode.parentNode)' type='button'>Edit</button>"); html.Append("</td>"); html.Append("<td>"); html.Append("<button onclick='deleteRole()' type='button'>Delete</button>"); html.Append("</td>"); html.Append("</tr>"); } html.Append("</tbody>"); //Append the HTML string to Placeholder. placeHolderTableRole.Controls.Clear(); placeHolderTableRole.Controls.Add(new Literal { Text = html.ToString() }); }
protected void InsertVehicle(Vehicle vehicle) { VehicleTypeData vehicleTypeData = new VehicleTypeData(); VehicleBussinessRules vehicleBussinessRules = new VehicleBussinessRules(); if (vehicle != null) { int insertResult = vehicleBussinessRules.InsertVehicle(vehicle, Session["User-UserName"].ToString()); switch (insertResult) { case 0: buttonStyle.buttonStyleBlue(buttonErrors, "Vehicle added sucessful."); FillTable(); break; case 1: buttonStyle.buttonStyleWhite(buttonErrors, "The license field is empty."); break; case 2: buttonStyle.buttonStyleRed(buttonErrors, "The license can only contain seven characters."); break; } } else { buttonStyle.buttonStyleRed(buttonErrors, "Invalid data, please check it."); } }
protected void FillVehicleType() { VehicleTypeData vehicleTypedata = new VehicleTypeData(); DataTable condition = vehicleTypedata.DataTableAllVehicleType(); selectType.DataSource = condition; selectType.DataTextField = "Name"; selectType.DataValueField = "Id"; selectType.DataBind(); }